home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / misc / emu / Frodo.lha / src / 6569.asm < prev    next >
Assembly Source File  |  1995-01-22  |  54KB  |  2,682 lines

  1. *
  2. * 6569.asm - VIC-Emulation
  3. *
  4. * Copyright (C) 1994-1995 by Christian Bauer
  5. *
  6.  
  7. *
  8. * Anmerkungen:
  9. * ------------
  10. *
  11. * Funktionsweise/Periodic:
  12. *  - Die VIC-Emulation arbeitet zeilenweise. Pro (simulierter)
  13. *    C64-Rasterzeile wird vom 6510-Task die Routine Periodic6569
  14. *    aufgerufen, die eine Pixelzeile der Grafik anhand der aktuellen
  15. *    Einstellungen in den VIC-Registern aufbaut. Dadurch können
  16. *    Rastereffekte sehr gut emuliert werden.
  17. *  - Die Emulation setzt eine 8-Bit-Chunky-Bitmap voraus und schreibt
  18. *    ihre Grafikdaten direkt dort hinein
  19. *  - Bei der Darstellung über die Amiga-Chips wird direkt in eine
  20. *    Chunky-Bitmap geschrieben, die beim VIC-VBlank in das planare Format
  21. *    konvertiert wird (mit c2p4), bei EGS/Picasso werden die Grafikdaten
  22. *    für eine Zeile in einen Puffer geschrieben, der am Ende der Zeile
  23. *    in den Grafikspeicher der Karte übertragen wird
  24. *  - Für eine sauberere Darstellung verwendet die Emulation Double
  25. *    Buffering. Es wird jeweils in eine unsichtbare Bitmap gezeichnet
  26. *    und bei einem VIC-VBlank werden die Puffer gewechselt.
  27. *  - Die Farbpalette besteht aus den 16 C64-Farben, 16mal wiederholt.
  28. *    Dadurch spart man sich das Ausmaskieren der unteren 4 Bit bei den
  29. *    VIC-Farbcodes. Allerdings muß dieses bei der Chunky->Planar-
  30. *    Konvertierung für die Amiga-Chips erfolgen (der Algorithmus
  31. *    setzt voraus, daß die oberen Nibbles Null sind).
  32. *  - Die Auswahl der 5 verschiedenen Darstellungsmodi (plus 3 ungültige,
  33. *    die einen schwarzen Bildschirm erzeugen) geschieht über den
  34. *    Zeiger DisplayProc, der auf die entsprechende Routine (z.B. TextStd,
  35. *    BitMapMulti etc.) zeigt und der bei einem Schreibzugriff auf eines
  36. *    der beiden Kontrollregister CTRL1/CTRL2 neu gesetzt wird
  37. *
  38. * 6510-Zyklenzähler
  39. *  - In jeder Rasterzeile wird der Zyklenzähler für die CPU neu gesetzt,
  40. *    und zwar unterschiedlich je nachdem, ob eine Bad Line stattfand
  41. *    oder nicht
  42. *  - Für jedes dargestellte Sprite werden nochmal je 2 Zyklen abgezogen
  43. *
  44. * Bad Lines:
  45. *  - Eine Bad Line ist dann, wenn $30 <= RASTER <= $f7 und
  46. *    die unteren drei Bits von RASTER mit den unteren drei Bits von
  47. *    Reg. $11 (Y-Scroll) übereinstimmen
  48. *  - In einer Bad Line werden 40 Bytes aus Videomatrix und Farb-RAM geholt
  49. *
  50. * Rasterzähler RC/Grafikdarstellung:
  51. *  - Der RC wird in jeder Bad Line auf Null gesetzt, gleichzeitig wird
  52. *    die Darstellung der Grafik angeschaltet (DISPLAYOFF wird gelöscht)
  53. *  - Am Ende einer Rasterzeile wird der RC um 1 erhöht, es sei denn,
  54. *    er steht auf 7. In diesem Fall wird die Darstellung ausgeschaltet.
  55. *  - Ist DISPLAYOFF gesetzt, wird in der Textspalte $3fff dargestellt,
  56. *    ansonsten Text oder Bitmapgrafik
  57. *  - Deshalb wird im oberen/unteren Rahmen immer $3fff dargestellt, weil
  58. *    es dort keine Bad Lines gibt und der RC nie zurückgesetzt wird
  59. *
  60. * Videomatrixzähler VC:
  61. *  - Es gibt zwei Register, VCBASE und VCCOUNT. Zum Zugriff auf die
  62. *    Grafikdaten wird VCCOUNT benutzt.
  63. *  - Beim VBlank wird VCBASE auf Null gesetzt
  64. *  - Zu Beginn jeder Zeile wird VCCOUNT mit dem Wert aus VCBASE geladen
  65. *  - Wenn DISPLAYOFF gelöscht ist und Grafik dargestellt wird, wird
  66. *    VCCOUNT um 40 erhöht (symbolisch für die 40 Zugriffe des VIC)
  67. *  - Wenn die Darstellung abgeschaltet wird, weil RC=7 ist (am Ende
  68. *    einer Zeile) wird VCBASE mit dem Wert aus VCCOUNT geladen
  69. *
  70. * Spritedatenzähler MCx/Spritedarstellung:
  71. *  - Da die Spritedaten beim VIC am Ende einer Rasterzeile geholt werden
  72. *    und daher die Y-Positionen der Sprites eins niedriger als die
  73. *    Rasterzeilennummern sind, werden die Spritedatenzähler in der
  74. *    Emulation am Ende einer Rasterzeile gehandhabt (nachdem die Sprites
  75. *    gezeichnet wurden)
  76. *  - Wenn ein Sprite eingeschaltet ist und die Y-Koordinate gleich den
  77. *    unteren 8 Bit von RASTER ist, wird der Datenzähler auf Null gesetzt
  78. *    und die Darstellung des Sprite eingeschaltet (Bit in SPRITEON).
  79. *    Jede folgende Rasterzeile wird der Zähler um 3 erhöht, solange er
  80. *    kleiner als 60 ist. Erreicht er 60, wird die Darstellung des Sprite
  81. *    ausgeschaltet. Wenn das Sprite Y-expandiert ist, wird der Zähler nur
  82. *    in den Zeilen erhöht, in denen die unteren Bits von Y-Koordinate und
  83. *    Zeilennummer gleich sind.
  84. *
  85. * X-Scroll>0 und 40 Spalten:
  86. *  - Wenn der X-Scroll>0 und die 40-Spalten-Darstellung eingeschaltet
  87. *    ist, hängt das, was am linken Bildrand dargestellt wird, vom
  88. *    aktuellen Grafikmodus ab
  89. *  - Im Standard-Text-, Multicolor-Text- und Multicolor-Bitmap-Modus wird
  90. *    dort die Hintergrundfarbe aus Reg.$21 dargestellt
  91. *  - Im Standard-Bitmap- und ECM-Text-Modus wird die Hintergrundfarbe
  92. *    der letzten 8 Pixel der vorherigen Zeile dargestellt
  93. *
  94. * Inkompatibilitäten:
  95. *  - Effekte, die durch die Änderung von VIC-Registern innerhalb einer
  96. *    Rasterzeile erreicht werden, können nicht emuliert werden
  97. *  - Keine Sprite-Grafik-Priorität
  98. *  - Keine Sprite-Hintergrund-Kollisionen
  99. *  - Sprite-Sprite-Kollisionen werden nur innerhalb des sichtbaren
  100. *    Bereiches erkannt
  101. *  - X-expandierte Sprites mit X-Koordinaten >=$140 werden nicht angezeigt.
  102. *    Genaugenommen sollte ein Sprite nur dann unsichtbar sein, wenn die
  103. *    X-Koordinate zwischen $1f8 und $1ff liegt.
  104. *  - In den Bitmap-Darstellungen ab den Adressen $0000 und $8000 sollte
  105. *    eigentlich ab $1000/$9000 das Char-ROM sichtbar sein. Aus
  106. *    Geschwindigkeitsgründen wird in der Emulation das RAM darunter
  107. *    dargestellt. Dies sollte keine Rolle spielen, da diese Bitmap-Seiten
  108. *    aus dem genannten Grund von keinem Programm komplett verwendet werden.
  109. *  - Der IRQ wird bei jedem Schreibzugriff in das Flag-Register gelöscht.
  110. *    Das ist ein Hack für die RMW-Befehle des 6510, die zuerst den
  111. *    Originalwert schreiben.
  112. *
  113. * Verbesserungen:
  114. *  - Amiga VBlank sollte Double Buffering verwenden
  115. *
  116.  
  117.         MACHINE    68020
  118.  
  119.         INCLUDE    "exec/types.i"
  120.         INCLUDE    "exec/macros.i"
  121.         INCLUDE    "exec/memory.i"
  122.         INCLUDE    "intuition/intuition.i"
  123.         INCLUDE    "graphics/displayinfo.i"
  124.         INCLUDE    "egs/egs.i"
  125.         INCLUDE    "devices/inputevent.i"
  126.  
  127.         XREF    _SysBase    ;Main.asm
  128.         XREF    _GfxBase
  129.         XREF    _IntuitionBase
  130.         XREF    _EGSBase
  131.         XREF    _VilIntuiBase
  132.  
  133.         XREF    TheRAM        ;6510.asm
  134.         XREF    TheChar
  135.         XREF    TheColor
  136.         XREF    IntIsVICIRQ
  137.         XREF    CyclesLeft
  138.         XREF    DontPause
  139.         XREF    CPUTask
  140.         XREF    Peri6569Cont
  141.  
  142.         XREF    CountTODs    ;6526.asm
  143.         XREF    KeyPressed
  144.  
  145.         XREF    _c2p4        ;c2p4.asm
  146.         XREF    Initc2p4
  147.         XREF    Exitc2p4
  148.  
  149.         XDEF    OpenGraphics
  150.         XDEF    CloseGraphics
  151.         XDEF    AmigaToFront
  152.         XDEF    EmulToFront
  153.         XDEF    WaitForClick
  154.         XDEF    ChangedVA
  155.         XDEF    Init6569
  156.         XDEF    Exit6569
  157.         XDEF    ReadFrom6569
  158.         XDEF    WriteTo6569
  159.         XDEF    Periodic6569
  160.  
  161.         XDEF    DisplayID    ;Prefs
  162.         XDEF    ScreenType    ;Prefs
  163.         XDEF    NormalCycles    ;Prefs
  164.         XDEF    BadLineCycles    ;Prefs
  165.  
  166.         SECTION    "CODE",CODE
  167.  
  168.  
  169. **
  170. ** Definitionen
  171. **
  172.  
  173. ; VIC-Register
  174. M0X        = $00    ;Position von Sprite 0
  175. M0Y        = $01
  176. M1X        = $02    ;Position von Sprite 1
  177. M1Y        = $03
  178. M2X        = $04    ;Position von Sprite 2
  179. M2Y        = $05
  180. M3X        = $06    ;Position von Sprite 3
  181. M3Y        = $07
  182. M4X        = $08    ;Position von Sprite 4
  183. M4Y        = $09
  184. M5X        = $0a    ;Position von Sprite 5
  185. M5Y        = $0b
  186. M6X        = $0c    ;Position von Sprite 6
  187. M6Y        = $0d
  188. M7X        = $0e    ;Position von Sprite 7
  189. M7Y        = $0f
  190. MX8        = $10    ;Höchste Bits der Sprite X-Positionen
  191. CTRL1        = $11    ;Steuerreg. 1
  192. RASTER        = $12    ;Rasterzähler
  193. SPREN        = $15    ;Sprite eingeschaltet
  194. CTRL2        = $16    ;Steuerreg. 2
  195. MYE        = $17    ;Sprite Y-Expansion
  196. VBASE        = $18    ;Basisadressen
  197. IRQFLAG        = $19    ;Interruptreg.
  198. IRQMASK        = $1a
  199. MMC        = $1c    ;Sprite Multicolor
  200. MXE        = $1d    ;Sprite X-Expansion
  201. CLXSPR        = $1e    ;Kollisionsreg.
  202. CLXBGR        = $1f
  203.  
  204. ; Zusätzliche Register
  205. DISPLAYOFF    = $2f    ;Flag: $3fff wird dargestellt
  206. IRQRASTER    = $30    ;Rasterzeile, bei der ein IRQ ausgelöst wird (Wort)
  207. XSCROLL        = $32    ;X-Scroll-Wert (Wort)
  208. YSCROLL        = $34    ;Y-Scroll-Wert (Wort)
  209. DXSTART        = $36    ;Aktuelle Werte des Randbereichs
  210. DXSTOP        = $38
  211. DYSTART        = $3a
  212. DYSTOP        = $3c
  213. RC        = $3e    ;Rasterzähler RC
  214. MATRIXBASE    = $40    ;Videomatrix-Basis (Amiga-Adresse)
  215. CHARBASE    = $44    ;Zeichengenerator-Basis (Amiga-Adresse)
  216. BITMAPBASE    = $48    ;Bitmap-Basis (Amiga-Adresse)
  217. CURRENTA5    = $4c    ;Augenblicklicher Zeiger im Bildschirmspeicher
  218.             ;Speicher für a5 zwischen Aufrufen von Periodic6569
  219. CURRENTRASTER    = $50    ;Augenblickliche Rasterzeile
  220.             ;Speicher für d7 zwischen Aufrufen von Periodic6569
  221. LASTBKGD    = $52    ;Letzte dargestellte Hintergrundfarbe
  222. SPRITEON    = $53    ;Sprite wird dargestellt, pro Sprite ein Bit
  223. BORDERON    = $54    ;Flag: Oberer/unterer Rahmen wird dargestellt
  224. IS38COL        = $55    ;Flag: 38 Spalten
  225. SCREENOFF    = $56    ;Flag: Bildschirm ist abgeschaltet, nur Rahmen darstellen
  226.             ;Bei jedem VBlank wird Bit 4 in $D011 getestet und
  227.             ; dieses Flag entsprechend gesetzt
  228. MC0        = $58    ;Spritedatenzähler 0
  229. MC1        = $5a
  230. MC2        = $5c
  231. MC3        = $5e
  232. MC4        = $60
  233. MC5        = $62
  234. MC6        = $64
  235. MC7        = $66    ;Spritedatenzähler 7
  236. VCBASE        = $68    ;VC-Zwischenspeicher
  237. VCCOUNT        = $6a    ;VC-Zähler
  238.  
  239. ; Anzahl Rasterzeilen
  240. TotalRasters    = $138
  241.  
  242. ; Textfenster-Koordinaten (Stop-Werte sind immer eins mehr)
  243. Row25YStart    = $33
  244. Row25YStop    = $fb
  245. Row24YStart    = $37
  246. Row24YStop    = $f7
  247.  
  248. Col40XStart    = $18
  249. Col40XStop    = $158
  250. Col38XStart    = $1f
  251. Col38XStop    = $14f
  252.  
  253. ; Erste und letzte mögliche Zeile für Bad Lines
  254. FirstDMALine    = $30
  255. LastDMALine    = $f7
  256.  
  257. ; Erste und letzte dargestellte Zeile
  258. FirstDispLine    = $10
  259. LastDispLine    = $11f    ;eigentlich $12b
  260.  
  261. ; Größe der Anzeige
  262. DisplayX    = $170
  263. DisplayY    = LastDispLine-FirstDispLine+1
  264.  
  265. ; ScreenTypes
  266. STYP_EGS    = 0
  267. STYP_PICASSO    = 1
  268. STYP_AMIGA    = 2
  269.  
  270. ; EGS
  271. E_OpenScreen    = -30
  272. E_CloseScreen    = -36
  273. E_ScreenToFront    = -60
  274. E_ScreenToBack    = -66
  275. E_ActivateEGSScreen = -72
  276. E_ActivateAmigaScreen = -78
  277. E_SetRGB8    = -84
  278. E_DisposeBitMap    = -132
  279. E_FlipMap    = -168
  280. E_AllocBitMap    = -198
  281.  
  282. ; Village
  283. OpenVillageScreen = -30
  284. CloseVillageScreen = -36
  285. LockVillageScreen = -42
  286. UnLockVillageScreen = -48
  287. OpenVillageScreenTagList = -114
  288. VillageGetBufAddr = -126
  289. VillageSetDisplayBuf = -132
  290.  
  291. TAVIS_FIRSTITEM    = TAG_USER+4711
  292. TAVIS_DOUBLE_BUFFER = TAVIS_FIRSTITEM+40
  293. TAVIS_DM_STRUCT    = TAVIS_FIRSTITEM+41
  294.  
  295.  
  296. *
  297. * Makros
  298. *
  299.  
  300. ; Aus einer VIC-16-Bit-Adresse die entsprechende Amiga-Adresse berechnen
  301. ; -> d0.w: 16-Bit-Adresse
  302. ; <- a0.l: 32-Bit-Adresse
  303. GetPhysical    MACRO
  304.         or.w    CiaVABase(pc),d0 ;VA14/15 dazunehmen
  305.         move.w    d0,d1
  306.         and.w    #$7000,d1
  307.         cmp.w    #$1000,d1
  308.         beq    \@1$
  309.         move.l    TheRAM(pc),a0
  310.         moveq    #0,d1
  311.         move.w    d0,d1
  312.         add.l    d1,a0
  313.         bra    \@2$
  314. \@1$        and.w    #$0fff,d0    ;$1000-$1fff, $9000-$9fff: Char-ROM
  315.         move.l    TheChar(pc),a0
  316.         add.w    d0,a0
  317. \@2$
  318.         ENDM
  319.  
  320. ; Sprite darstellen
  321. DoSprite    MACRO    ;Nummer
  322.         move.b    $27+\1(a4),d2
  323.         lsl.w    #8,d2
  324.         move.b    $27+\1(a4),d2    ;d2: Spritefarbe
  325.         move.w    MC\1(a4),d5    ;d5: Datenzähler
  326.         moveq    #\1,d6        ;d6: Spritenummer
  327.         move.l    MATRIXBASE(a4),a0
  328.         move.b    $03f8+\1(a0),d7    ;d7: Datenzeiger
  329.         lea    M\1X(a4),a2    ;a2: Zeiger auf X-Koordinate
  330.         bsr    DrawSprite
  331.         ENDM
  332.  
  333.  
  334. **
  335. ** Bildschirm öffnen
  336. ** Rückgabe: d0=0 Alles OK
  337. **           d0=1 Fehler beim Screen-Öffnen
  338. **           d0=2 Kein Speicher
  339. **           d0=3 Kein EGS
  340. **           d0=4 Kein VilIntuiSup
  341. **           d0=5 Probleme mit DisplayID
  342. **           d0=6 Screen zu klein (min. 384×288)
  343. **
  344.  
  345. ; Kollisionsflag-Tabelle berechnen
  346. OpenGraphics    lea    SprCollTab,a0    ;Vorgabe: Kollision
  347.         moveq    #256/4-1,d0
  348. 1$        move.l    #-1,(a0)+
  349.         dbra    d0,1$
  350.  
  351.         lea    SprCollTab,a0    ;Keine Kollision bei nur einem Sprite
  352.         clr.w    (a0)
  353.         clr.b    2(a0)
  354.         clr.b    4(a0)
  355.         clr.b    8(a0)
  356.         clr.b    16(a0)
  357.         clr.b    32(a0)
  358.         clr.b    64(a0)
  359.         clr.b    128(a0)
  360.  
  361. ; Name des ScreenMode holen
  362.         move.l    _GfxBase,a6
  363.         sub.l    a0,a0
  364.         lea    ModeNameBuf,a1
  365.         moveq    #nif_SIZEOF,d0
  366.         move.l    #DTAG_NAME,d1
  367.         move.l    DisplayID,d2
  368.         JSRLIB    GetDisplayInfoData
  369.         tst.l    d0
  370.         beq    NoDisplayID
  371.  
  372. ; Register vorbereiten
  373.         lea    Registers,a0
  374.         move.w    #7,RC(a0)
  375.         move.w    #-1,CURRENTRASTER(a0)
  376.         move.l    TheRAM,MATRIXBASE(a0)
  377.         move.l    TheRAM,CHARBASE(a0)
  378.         move.l    TheRAM,BITMAPBASE(a0)
  379.         clr.w    CiaVABase
  380.         move.l    #TextStd,DisplayProc
  381.  
  382. ; Screen-Typ auswerten (Amiga)
  383.         cmp.w    #STYP_AMIGA,ScreenType
  384.         beq    OpenAmiga
  385.  
  386. ; EGS/Picasso: Dimensionen holen und prüfen, ob ausreichend
  387.         move.l    _IntuitionBase,a6
  388.         move.l    DisplayID,a0
  389.         lea    TheRect,a1
  390.         moveq    #OSCAN_TEXT,d0
  391.         JSRLIB    QueryOverscan
  392.         tst.l    d0
  393.         beq    NoDisplayID
  394.  
  395.         lea    TheRect,a0
  396.         move.w    ra_MaxX(a0),d0
  397.         sub.w    ra_MinX(a0),d0
  398.         addq.w    #1,d0
  399.         move.w    d0,ScreenX
  400.         move.w    ra_MaxY(a0),d0
  401.         sub.w    ra_MinY(a0),d0
  402.         addq.w    #1,d0
  403.         move.w    d0,ScreenY
  404.  
  405.         cmp.w    #384,ScreenX
  406.         blo    TooSmall
  407.         cmp.w    #288,ScreenY
  408.         blo    TooSmall
  409.  
  410. ; Screen-Typ auswerten (EGS/Picasso)
  411.         cmp.w    #STYP_EGS,ScreenType
  412.         beq    OpenEGS
  413.         bra    OpenPicasso
  414.  
  415. *
  416. * Amiga-Screen öffnen
  417. *
  418.  
  419. ; Screen öffnen
  420. OpenAmiga    move.w    #$180,d0        ;Vielfaches von 32 (wegen c2p)
  421.         move.w    d0,ScreenX
  422.         move.w    d0,WindowWidth+2
  423.         move.w    #DisplayY,d0
  424.         move.w    d0,ScreenY
  425.         move.w    d0,WindowHeight+2
  426.         move.l    DisplayID,ScreenDID
  427.  
  428.         bsr    Initc2p4
  429.         tst.l    d0
  430.         beq    NoMem
  431.  
  432.         move.l    _IntuitionBase,a6
  433.         sub.l    a0,a0
  434.         lea    ScreenTags,a1
  435.         JSRLIB    OpenScreenTagList
  436.         move.l    d0,TheScreen
  437.         beq    NoScreen
  438.         move.l    d0,WindowScreen
  439.  
  440.         move.l    TheScreen,a0
  441.         lea    sc_RastPort(a0),a1
  442.         move.l    a1,TheRastPort
  443.         lea    sc_ViewPort(a0),a1
  444.         move.l    a1,TheViewPort
  445.  
  446. ; Speicher für Chunky-BitMap und Comparison Buffer holen
  447.         move.l    _SysBase,a6
  448.         move.w    ScreenX,d0
  449.         mulu.w    #DisplayY,d0
  450.         add.l    d0,d0
  451.         move.l    #MEMF_PUBLIC|MEMF_CLEAR,d1
  452.         JSRLIB    AllocVec
  453.         move.l    d0,InvisibleMap
  454.         beq    NoMem
  455.         move.w    ScreenX,d1
  456.         mulu.w    #DisplayY,d1
  457.         add.l    d1,d0
  458.         move.l    d0,ComparisonBuf
  459.  
  460. ; Fenster öffnen
  461.         move.l    _IntuitionBase,a6
  462.         sub.l    a0,a0
  463.         lea    WindowTags,a1
  464.         JSRLIB    OpenWindowTagList
  465.         move.l    d0,TheWindow
  466.         beq    NoMem
  467.  
  468.         move.l    TheWindow,a0
  469.         move.l    wd_UserPort(a0),WindowPort
  470.  
  471. ; Farbpalette laden
  472.         move.l    _GfxBase,a6
  473.         moveq    #0,d7        ;Registerzähler
  474.         lea    Palette,a2
  475. 1$        move.b    d7,d0
  476.         and.w    #$0f,d0
  477.         lea    (a2,d0.w*4),a0
  478.         moveq    #0,d1
  479.         move.b    (a0)+,d1
  480.         lsr.b    #4,d1
  481.         moveq    #0,d2
  482.         move.b    (a0)+,d2
  483.         lsr.b    #4,d2
  484.         moveq    #0,d3
  485.         move.b    (a0)+,d3
  486.         lsr.b    #4,d3
  487.         move.l    d7,d0
  488.         move.l    TheViewPort,a0
  489.         JSRLIB    SetRGB4
  490.         addq.b    #1,d7
  491.         cmp.b    #16,d7        ;Hier nur 16 Register
  492.         bne    1$
  493.  
  494. ; Adresse des Bildschirmspeichers setzen
  495.         move.l    InvisibleMap,Registers+CURRENTA5
  496.         clr.w    MustWaitForC2P
  497.  
  498. ; VBlank-Routine setzen
  499.         move.l    #AmigaVBlank,VBlankProc
  500.  
  501.         moveq    #0,d0
  502.         rts
  503.  
  504. *
  505. * Picasso-Screen öffnen
  506. *
  507.  
  508. ; VilIntuiSup vorhanden?
  509. OpenPicasso    tst.l    _VilIntuiBase
  510.         beq    NoVilIntuiSup
  511.  
  512. ; Screen öffnen
  513.         move.w    ScreenX,WindowWidth+2
  514.         move.w    ScreenY,WindowHeight+2
  515.  
  516.         move.l    _VilIntuiBase,a6
  517.         lea    Dimensions,a0
  518.         move.w    ScreenX,4(a0)
  519.         move.w    ScreenY,6(a0)
  520.         lea    VilTags,a0
  521.         jsr    OpenVillageScreenTagList(a6)
  522.         move.l    d0,TheScreen
  523.         beq    NoScreen
  524.         move.l    d0,WindowScreen
  525.  
  526.         move.l    TheScreen,a0
  527.         lea    sc_ViewPort(a0),a1
  528.         move.l    a1,TheViewPort
  529.  
  530. ; Fenster öffnen
  531.         move.l    _IntuitionBase,a6
  532.         sub.l    a0,a0
  533.         lea    WindowTags,a1
  534.         JSRLIB    OpenWindowTagList
  535.         move.l    d0,TheWindow
  536.         beq    NoMem
  537.  
  538.         move.l    TheWindow,a0
  539.         move.l    wd_UserPort(a0),WindowPort
  540.  
  541. ; Farbpalette laden
  542.         move.l    _GfxBase,a6
  543.         moveq    #0,d7        ;Registerzähler
  544.         lea    Palette,a2
  545. 1$        move.b    d7,d0
  546.         and.w    #$0f,d0
  547.         lea    (a2,d0.w*4),a0
  548.         moveq    #0,d1
  549.         move.b    (a0)+,d1
  550.         moveq    #0,d2
  551.         move.b    (a0)+,d2
  552.         moveq    #0,d3
  553.         move.b    (a0)+,d3
  554.         move.l    d7,d0
  555.         move.l    TheViewPort,a0
  556.         JSRLIB    SetRGB4
  557.         addq.b    #1,d7
  558.         bne    1$
  559.  
  560. ; Adresse des Bildschirmspeichers setzen
  561.         move.l    #1,InvBufNum        ;Adresse des zweiten Puffers holen
  562.         move.l    _VilIntuiBase,a6
  563.         move.l    TheScreen,a0
  564.         jsr    LockVillageScreen(a6)
  565.         move.l    TheScreen,a0
  566.         move.l    InvBufNum,d0
  567.         jsr    VillageGetBufAddr(a6)
  568.         move.l    d0,Registers+CURRENTA5
  569.  
  570. ; VBlank-Routine setzen
  571.         move.l    #PicassoVBlank,VBlankProc
  572.  
  573.         moveq    #0,d0
  574.         rts
  575.  
  576. *
  577. * EGS-Screen öffnen
  578. *
  579.  
  580. ; EGS vorhanden?
  581. OpenEGS        tst.l    _EGSBase
  582.         beq    NoEGS
  583.  
  584. ; Screen öffnen
  585.         move.l    _EGSBase,a6
  586.         lea    NewEScreen,a0
  587.         jsr    E_OpenScreen(a6)
  588.         move.l    d0,TheScreen
  589.         beq    NoScreen
  590.  
  591.         move.l    TheScreen,a0
  592.         move.l    esc_Port(a0),EGSPort
  593.  
  594. ; Zweite Bitmap für Double Buffering holen
  595.         moveq    #0,d0
  596.         move.w    ScreenX,d0
  597.         moveq    #0,d1
  598.         move.w    ScreenY,d1
  599.         moveq    #8,d2
  600.         moveq    #0,d3
  601.         move.l    #E_EB_DISPLAYABLE|E_EB_CLEARMAP,d4
  602.         move.l    TheScreen,a0
  603.         move.l    esc_Map(a0),a0
  604.         jsr    E_AllocBitMap(a6)
  605.         move.l    d0,InvisibleMap
  606.         beq    NoMem
  607.  
  608. ; Farbpalette laden
  609.         moveq    #0,d7        ;Registerzähler
  610.         lea    Palette,a2
  611. 1$        move.b    d7,d0
  612.         and.w    #$0f,d0
  613.         lea    (a2,d0.w*4),a0
  614.         moveq    #0,d1
  615.         move.b    (a0)+,d1
  616.         moveq    #0,d2
  617.         move.b    (a0)+,d2
  618.         moveq    #0,d3
  619.         move.b    (a0)+,d3
  620.         move.l    d7,d0
  621.         move.l    TheScreen,a0
  622.         jsr    E_SetRGB8(a6)
  623.         addq.b    #1,d7
  624.         bne    1$
  625.  
  626. ; Adresse des Bildschirmspeichers setzen
  627.         move.l    InvisibleMap,a1
  628.         addq.b    #1,ebm_Lock(a1)
  629.         move.l    ebm_Dest(a1),Registers+CURRENTA5
  630.  
  631. ; VBlank-Routine setzen
  632.         move.l    #EGSVBlank,VBlankProc
  633.  
  634.         moveq    #0,d0
  635.         rts
  636.  
  637. ; Fehler aufgetreten
  638. NoScreen    moveq    #1,d0
  639.         rts
  640. NoMem        moveq    #2,d0
  641.         rts
  642. NoEGS        moveq    #3,d0
  643.         rts
  644. NoVilIntuiSup    moveq    #4,d0
  645.         rts
  646. NoDisplayID    moveq    #5,d0
  647.         rts
  648. TooSmall    moveq    #6,d0
  649.         rts
  650.  
  651.  
  652. **
  653. ** Bildschirm schließen
  654. **
  655.  
  656. CloseGraphics    cmp.w    #STYP_EGS,ScreenType
  657.         beq    CloseEGS
  658.         cmp.w    #STYP_PICASSO,ScreenType
  659.         beq    ClosePicasso
  660.  
  661. ; Amiga
  662. CloseAmiga    move.l    _IntuitionBase,a6
  663.         move.l    TheWindow,d0
  664.         beq    1$
  665.         move.l    d0,a0
  666.         JSRLIB    CloseWindow
  667.  
  668. 1$        move.l    TheScreen,d0
  669.         beq    2$
  670.         move.l    d0,a0
  671.         JSRLIB    CloseScreen
  672.  
  673. 2$        move.l    InvisibleMap,d0
  674.         beq    3$
  675.         move.l    _SysBase,a6
  676.         move.l    d0,a1
  677.         JSRLIB    FreeVec
  678.  
  679. 3$        bsr    Exitc2p4
  680.  
  681.         rts
  682.  
  683. ; Picasso
  684. ClosePicasso    move.l    _IntuitionBase,a6
  685.         move.l    TheWindow,d0
  686.         beq    1$
  687.         move.l    d0,a0
  688.         JSRLIB    CloseWindow
  689.  
  690. 1$        move.l    _VilIntuiBase,a6
  691.         move.l    TheScreen,d0
  692.         beq    2$
  693.         move.l    d0,a0
  694.         jsr    UnLockVillageScreen(a6)
  695.         move.l    TheScreen,a0
  696.         jsr    CloseVillageScreen(a6)
  697.  
  698. 2$        rts
  699.  
  700. ; EGS
  701. CloseEGS    move.l    _EGSBase,a6
  702.         move.l    TheScreen,d0
  703.         beq    1$
  704.         move.l    d0,a0
  705.         jsr    E_CloseScreen(a6)
  706.  
  707. 1$        move.l    InvisibleMap,d0
  708.         beq    2$
  709.         move.l    d0,a0
  710.         subq.b    #1,ebm_Lock(a0)
  711.         jsr    E_DisposeBitMap(a6)
  712.  
  713. 2$        rts
  714.  
  715.  
  716. **
  717. ** Amiga-Anzeige nach vorne
  718. **
  719.  
  720. AmigaToFront    cmp.w    #STYP_EGS,ScreenType
  721.         beq    ATFEGS
  722.  
  723. ; Amiga/Picasso
  724.         move.l    a6,-(sp)
  725.         move.l    _IntuitionBase,a6
  726.         move.l    TheScreen,a0
  727.         JSRLIB    ScreenToBack
  728.         move.l    (sp)+,a6
  729.         rts
  730.  
  731. ; EGS
  732. ATFEGS        move.l    a6,-(sp)
  733.         move.l    _EGSBase,a6
  734.         jsr    E_ActivateAmigaScreen(a6)
  735.         move.l    TheScreen,a0
  736.         jsr    E_ScreenToBack(a6)
  737.         move.l    (sp)+,a6
  738.         rts
  739.  
  740.  
  741. **
  742. ** Emulator-Anzeige nach vorne
  743. **
  744.  
  745. EmulToFront    cmp.w    #STYP_EGS,ScreenType
  746.         beq    ETFEGS
  747.  
  748. ; Amiga/Picasso
  749.         move.l    a6,-(sp)
  750.         move.l    _IntuitionBase,a6
  751.         move.l    TheScreen,a0
  752.         JSRLIB    ScreenToFront
  753.         move.l    (sp)+,a6
  754.         rts
  755.  
  756. ; EGS
  757. ETFEGS        move.l    a6,-(sp)
  758.         move.l    _EGSBase,a6
  759.         jsr    E_ActivateEGSScreen(a6)
  760.         move.l    TheScreen,a0
  761.         jsr    E_ScreenToFront(a6)
  762.         move.l    (sp)+,a6
  763.         rts
  764.  
  765.  
  766. **
  767. ** Auf rechten Mausklick warten, Tastatur handhaben
  768. **
  769.  
  770. WaitForClick    cmp.w    #STYP_EGS,ScreenType
  771.         beq    WFCEGS
  772.  
  773. ; Amiga/Picasso
  774. WFCAmiga    move.l    _SysBase,a6
  775.         move.l    WindowPort,a0
  776.         JSRLIB    WaitPort
  777.  
  778.         move.l    WindowPort,a0
  779.         JSRLIB    GetMsg
  780.         tst.l    d0
  781.         beq    WFCAmiga
  782.         move.l    d0,a1
  783.         move.l    20(a1),d2    ;d2: Class
  784.         move.w    24(a1),d3    ;d3: Code
  785.         move.l    32(a1),d4    ;d4: MouseXY
  786.         move.w    26(a1),d5    ;d5: Qualifier
  787.         JSRLIB    ReplyMsg
  788.  
  789. ; Klasse auswerten
  790.         cmp.l    #IDCMP_MOUSEBUTTONS,d2
  791.         bne    1$
  792.         cmp.w    #IECODE_RBUTTON,d3 ;Rechte Maustaste: Beenden
  793.         beq    WFCDone
  794.         bra    WFCAmiga
  795.  
  796. 1$        cmp.l    #IDCMP_RAWKEY,d2
  797.         bne    WFCAmiga
  798.         move.b    d3,d0
  799.         bsr    KeyPressed    ;Tastaturabfrage
  800.         bra    WFCAmiga
  801.  
  802. ; EGS
  803. WFCEGS        move.l    _SysBase,a6
  804.         move.l    EGSPort,a0
  805.         JSRLIB    WaitPort
  806.  
  807.         move.l    EGSPort,a0
  808.         JSRLIB    GetMsg
  809.         tst.l    d0
  810.         beq    WFCEGS
  811.         move.l    d0,a1
  812.         move.l    20(a1),d2    ;d2: Class
  813.         move.w    24(a1),d3    ;d3: Code
  814.         move.l    32(a1),d4    ;d4: MouseXY
  815.         move.w    26(a1),d5    ;d5: Qualifier
  816.         JSRLIB    ReplyMsg
  817.  
  818. ; Klasse auswerten
  819.         cmp.w    #E_eMOUSEBUTTONS,d2
  820.         bne    1$
  821.         cmp.w    #IECODE_RBUTTON,d3 ;Rechte Maustaste: Beenden
  822.         beq    WFCDone
  823.         bra    WFCEGS
  824.  
  825. 1$        cmp.w    #E_eRAWKEY,d2
  826.         bne    WFCEGS
  827.         move.b    d3,d0
  828.         bsr    KeyPressed    ;Tastaturabfrage
  829.         bra    WFCEGS
  830.  
  831. ; Beenden
  832. WFCDone        rts
  833.  
  834.  
  835. **
  836. ** CIA-VA14/15 hat sich geändert, Video-Bank wechseln
  837. ** d0.b: Neue VA ($00-$03)
  838. **
  839.  
  840. ChangedVA    lea    Registers,a0    ;Wichtig für WrVBASE
  841.         clr.w    d1        ;VABase speichern
  842.         move.b    d0,d1
  843.         ror.w    #2,d1
  844.         move.w    d1,CiaVABase
  845.  
  846.         move.b    VBASE(a0),d1 ;Zeiger neu berechnen
  847.         bra    WrVBASE
  848.  
  849.  
  850. **
  851. ** Initialisierung vom 6510-Task aus
  852. **
  853.  
  854. ; Signal für c2p4 holen
  855. Init6569    move.l    _SysBase,a6
  856.         moveq    #-1,d0
  857.         JSRLIB    AllocSignal
  858.         move.b    d0,GfxSig
  859.         moveq    #0,d1
  860.         bset    d0,d1
  861.         move.l    d1,GfxSet
  862.         rts
  863.  
  864.  
  865. **
  866. ** Aufräumen vom 6510-Task aus
  867. **
  868.  
  869. ; Ggf. auf Signal von c2p4 warten
  870. Exit6569    tst.w    MustWaitForC2P
  871.         beq    1$
  872.         move.l    _SysBase,a6
  873.         move.l    GfxSet,d0
  874.         JSRLIB    Wait
  875. 1$        rts
  876.  
  877.  
  878. **
  879. ** Aus einem VIC-Register lesen
  880. ** d0.w: Registernummer ($00-$3f)
  881. ** Rückgabe: d0.b: Byte
  882. **
  883. ** Darf das obere Wort von d0 und d1 nicht verändern!
  884. ** Darf a1 nicht verändern!
  885. **
  886.  
  887. ReadFrom6569    move.l    ReadTab(pc,d0.w*4),a0
  888.         jmp    (a0)
  889.  
  890.         CNOP    0,4
  891. ReadTab        dc.l    RdNormal
  892.         dc.l    RdNormal
  893.         dc.l    RdNormal
  894.         dc.l    RdNormal
  895.         dc.l    RdNormal
  896.         dc.l    RdNormal
  897.         dc.l    RdNormal
  898.         dc.l    RdNormal
  899.         dc.l    RdNormal
  900.         dc.l    RdNormal
  901.         dc.l    RdNormal
  902.         dc.l    RdNormal
  903.         dc.l    RdNormal
  904.         dc.l    RdNormal
  905.         dc.l    RdNormal
  906.         dc.l    RdNormal
  907.  
  908.         dc.l    RdNormal
  909.         dc.l    RdCTRL1
  910.         dc.l    RdRASTER
  911.         dc.l    RdNormal
  912.         dc.l    RdNormal
  913.         dc.l    RdNormal
  914.         dc.l    RdCTRL2
  915.         dc.l    RdNormal
  916.         dc.l    RdVBASE
  917.         dc.l    RdIRQFLAG
  918.         dc.l    RdIRQMASK
  919.         dc.l    RdNormal
  920.         dc.l    RdNormal
  921.         dc.l    RdNormal
  922.         dc.l    RdCLXSPR
  923.         dc.l    RdCLXBGR
  924.  
  925.         dc.l    RdColor
  926.         dc.l    RdColor
  927.         dc.l    RdColor
  928.         dc.l    RdColor
  929.         dc.l    RdColor
  930.         dc.l    RdColor
  931.         dc.l    RdColor
  932.         dc.l    RdColor
  933.         dc.l    RdColor
  934.         dc.l    RdColor
  935.         dc.l    RdColor
  936.         dc.l    RdColor
  937.         dc.l    RdColor
  938.         dc.l    RdColor
  939.         dc.l    RdColor
  940.         dc.l    RdUndef
  941.  
  942.         dc.l    RdUndef
  943.         dc.l    RdUndef
  944.         dc.l    RdUndef
  945.         dc.l    RdUndef
  946.         dc.l    RdUndef
  947.         dc.l    RdUndef
  948.         dc.l    RdUndef
  949.         dc.l    RdUndef
  950.         dc.l    RdUndef
  951.         dc.l    RdUndef
  952.         dc.l    RdUndef
  953.         dc.l    RdUndef
  954.         dc.l    RdUndef
  955.         dc.l    RdUndef
  956.         dc.l    RdUndef
  957.         dc.l    RdUndef
  958.  
  959. RdNormal    lea    Registers,a0
  960.         move.b    (a0,d0.w),d0
  961.         rts
  962.  
  963. RdColor        lea    Registers,a0
  964.         move.b    (a0,d0.w),d0        ;Bei den Farbregistern
  965.         or.b    #$f0,d0            ;das obere Nibble setzen
  966.         rts
  967.  
  968. RdUndef        move.b    #$ff,d0            ;Nicht existierendes Register
  969.         rts
  970.  
  971. RdCTRL1        lea    Registers,a0
  972.         move.b    CTRL1(a0),d0
  973.         and.b    #$7f,d0
  974.         move.b    CURRENTRASTER(a0),d1    ;MSB des Rasterzählers lesen
  975.         and.b    #$01,d1
  976.         ror.b    #1,d1
  977.         or.b    d1,d0            ;und dazunehmen
  978.         rts
  979.  
  980. RdRASTER    move.b    Registers+CURRENTRASTER+1,d0 ;Rasterzähler lesen
  981.         rts
  982.  
  983. RdCTRL2        move.b    Registers+CTRL2,d0
  984.         or.b    #$c0,d0            ;Unbenutzte Bits auf 1
  985.         rts
  986.  
  987. RdVBASE        move.b    Registers+VBASE,d0
  988.         or.b    #$01,d0            ;Unbenutzte Bits auf 1
  989.         rts
  990.  
  991. RdIRQFLAG    move.b    Registers+IRQFLAG,d0
  992.         or.b    #$70,d0            ;Unbenutzte Bits auf 1
  993.         rts
  994.  
  995. RdIRQMASK    move.b    Registers+IRQMASK,d0
  996.         or.b    #$f0,d0            ;Unbenutzte Bits auf 1
  997.         rts
  998.  
  999. RdCLXSPR    lea    Registers+CLXSPR,a0
  1000.         move.b    (a0),d0            ;Lesen und löschen
  1001.         clr.b    (a0)
  1002.         rts
  1003.  
  1004. RdCLXBGR    lea    Registers+CLXBGR,a0
  1005.         move.b    (a0),d0            ;Lesen und löschen
  1006.         clr.b    (a0)
  1007.         rts
  1008.  
  1009.  
  1010. **
  1011. ** In ein VIC-Register schreiben
  1012. ** d0.w: Registernummer ($00-$3f)
  1013. ** d1.b: Byte
  1014. **
  1015. ** Darf das obere Wort von d0 und d1 nicht verändern!
  1016. **
  1017.  
  1018. WriteTo6569    lea    Registers,a0
  1019.         move.l    WriteTab(pc,d0.w*4),a1
  1020.         jmp    (a1)
  1021.  
  1022.         CNOP    0,4
  1023. WriteTab    dc.l    WrNormal
  1024.         dc.l    WrNormal
  1025.         dc.l    WrNormal
  1026.         dc.l    WrNormal
  1027.         dc.l    WrNormal
  1028.         dc.l    WrNormal
  1029.         dc.l    WrNormal
  1030.         dc.l    WrNormal
  1031.         dc.l    WrNormal
  1032.         dc.l    WrNormal
  1033.         dc.l    WrNormal
  1034.         dc.l    WrNormal
  1035.         dc.l    WrNormal
  1036.         dc.l    WrNormal
  1037.         dc.l    WrNormal
  1038.         dc.l    WrNormal
  1039.  
  1040.         dc.l    WrNormal
  1041.         dc.l    WrCTRL1
  1042.         dc.l    WrRASTER
  1043.         dc.l    WrNormal
  1044.         dc.l    WrNormal
  1045.         dc.l    WrNormal
  1046.         dc.l    WrCTRL2
  1047.         dc.l    WrNormal
  1048.         dc.l    WrVBASE
  1049.         dc.l    WrIRQFLAG
  1050.         dc.l    WrIRQMASK
  1051.         dc.l    WrNormal
  1052.         dc.l    WrNormal
  1053.         dc.l    WrNormal
  1054.         dc.l    WrUndef
  1055.         dc.l    WrUndef
  1056.  
  1057.         dc.l    WrColor
  1058.         dc.l    WrColor
  1059.         dc.l    WrColor
  1060.         dc.l    WrColor
  1061.         dc.l    WrColor
  1062.         dc.l    WrNormal
  1063.         dc.l    WrNormal
  1064.         dc.l    WrNormal
  1065.         dc.l    WrNormal
  1066.         dc.l    WrNormal
  1067.         dc.l    WrNormal
  1068.         dc.l    WrNormal
  1069.         dc.l    WrNormal
  1070.         dc.l    WrNormal
  1071.         dc.l    WrNormal
  1072.         dc.l    WrUndef
  1073.  
  1074.         dc.l    WrUndef
  1075.         dc.l    WrUndef
  1076.         dc.l    WrUndef
  1077.         dc.l    WrUndef
  1078.         dc.l    WrUndef
  1079.         dc.l    WrUndef
  1080.         dc.l    WrUndef
  1081.         dc.l    WrUndef
  1082.         dc.l    WrUndef
  1083.         dc.l    WrUndef
  1084.         dc.l    WrUndef
  1085.         dc.l    WrUndef
  1086.         dc.l    WrUndef
  1087.         dc.l    WrUndef
  1088.         dc.l    WrUndef
  1089.         dc.l    WrUndef
  1090.  
  1091. WrColor        and.b    #$0f,d1
  1092. WrNormal    move.b    d1,(a0,d0.w)
  1093. WrUndef        rts
  1094.  
  1095. WrCTRL1        move.b    d1,CTRL1(a0)
  1096.         move.b    d1,d0
  1097.         and.w    #7,d0
  1098.         move.w    d0,YSCROLL(a0)
  1099.         move.b    d1,d0        ;MSB Raster
  1100.         and.b    #$80,d0
  1101.         rol.b    #1,d0
  1102.         move.b    d0,IRQRASTER(a0)
  1103.         btst    #3,d1        ;24/25 Zeilen
  1104.         beq    1$
  1105.         move.w    #Row25YStart,DYSTART(a0)
  1106.         move.w    #Row25YStop,DYSTOP(a0)
  1107.         bra    SetDispProc
  1108. 1$        move.w    #Row24YStart,DYSTART(a0)
  1109.         move.w    #Row24YStop,DYSTOP(a0)
  1110.         bra    SetDispProc
  1111.  
  1112. WrRASTER    move.b    d1,IRQRASTER+1(a0)
  1113.         rts
  1114.  
  1115. WrCTRL2        move.b    d1,CTRL2(a0)
  1116.         move.b    d1,d0
  1117.         and.w    #7,d0
  1118.         move.w    d0,XSCROLL(a0)
  1119.         btst    #3,d1        ;38/40 Zeilen
  1120.         beq    1$
  1121.         clr.b    IS38COL(a0)
  1122.         move.w    #Col40XStart,DXSTART(a0)
  1123.         move.w    #Col40XStop,DXSTOP(a0)
  1124.         bra    SetDispProc
  1125. 1$        st.b    IS38COL(a0)
  1126.         move.w    #Col38XStart,DXSTART(a0)
  1127.         move.w    #Col38XStop,DXSTOP(a0)
  1128.         bra    SetDispProc
  1129.  
  1130. SetDispProc    moveq    #0,d0        ;ECM, BMM und MCM holen
  1131.         move.b    CTRL1(a0),d0
  1132.         and.b    #$60,d0
  1133.         move.b    CTRL2(a0),d1
  1134.         and.b    #$10,d1
  1135.         or.b    d1,d0
  1136.         lsr.b    #2,d0        ;Als Index in DispProcTab benutzen
  1137.         move.l    (DispProcTab,pc,d0.w),DisplayProc
  1138.         rts
  1139.  
  1140. WrVBASE        move.l    a0,a1        ;a1: Zeiger auf Register
  1141.         move.b    d1,VBASE(a1)
  1142.  
  1143.         move.w    d1,-(sp)
  1144.         move.b    d1,d0        ;Videomatrixbasis berechnen
  1145.         and.w    #$f0,d0
  1146.         lsl.w    #6,d0
  1147.         GetPhysical
  1148.         move.l    a0,MATRIXBASE(a1)
  1149.         move.w    (sp),d1        ;Nur lesen, nicht entfernen
  1150.  
  1151.         move.b    d1,d0        ;Zeichengeneratorbasis berechnen
  1152.         and.w    #$0e,d0
  1153.         ror.w    #6,d0
  1154.         GetPhysical
  1155.         move.l    a0,CHARBASE(a1)
  1156.         move.w    (sp)+,d1
  1157.  
  1158.         move.b    d1,d0
  1159.         and.w    #$08,d0
  1160.         ror.w    #6,d0
  1161.         GetPhysical
  1162.         move.l    a0,BITMAPBASE(a1)
  1163.         rts
  1164.  
  1165. WrIRQFLAG    not.b    d1        ;Gesetztes Bit: Flag löschen
  1166.         and.b    #$0f,d1
  1167.         move.b    IRQFLAG(a0),d0
  1168.         and.b    d1,d0
  1169.  
  1170.         clr.b    IntIsVICIRQ    ;IRQ zurücknehmen
  1171.  
  1172.         move.b    d0,d1        ;Erlaubter IRQ noch gesetzt?
  1173.         and.b    IRQMASK(a0),d1
  1174.         beq    1$
  1175.         or.b    #$80,d0        ;Ja, Master-Bit setzen
  1176. 1$        move.b    d0,IRQFLAG(a0)
  1177.         rts
  1178.  
  1179. WrIRQMASK    and.b    #$0f,d1
  1180.         move.b    d1,IRQMASK(a0)
  1181.         rts
  1182.  
  1183.  
  1184. **
  1185. ** Eine Rasterzeile des VIC ausführen
  1186. **
  1187. ** d7: Rasterzeilenzähler
  1188. ** a4: Zeiger auf VIC-Register
  1189. ** a5: Zeiger auf das Ziel im Bildschirmspeicher
  1190. **
  1191.  
  1192. ; VBlank: Zähler zurücksetzen und Bitmap wechseln
  1193. VICVBlank    move.w    #-1,CURRENTRASTER(a4)
  1194.         clr.w    VCBASE(a4)
  1195.  
  1196.         btst    #4,CTRL1(a4)        ;Bildschirm abschalten, wenn DEN gelöscht
  1197.         bne    1$
  1198.         st.b    SCREENOFF(a4)
  1199.         bra    2$
  1200. 1$        clr.b    SCREENOFF(a4)
  1201. 2$
  1202.         bsr    CountTODs        ;TODs zählen
  1203.  
  1204.         move.l    VBlankProc,a0
  1205.         jmp    (a0)
  1206.  
  1207. ; EGS: BitMap wechseln (Double Buffering)
  1208. EGSVBlank    move.w    #-1,DontPause        ;Nicht hier anhalten
  1209.         move.l    a6,-(sp)
  1210.         move.l    _EGSBase(pc),a6        ;Vorher unsichtbare Bitmap
  1211.  
  1212.         move.l    TheScreen,a0        ;darstellen
  1213.         move.l    InvisibleMap,a1
  1214.         subq.b    #1,ebm_Lock(a1)
  1215.         jsr    E_FlipMap(a6)
  1216.         move.l    d0,InvisibleMap        ;In alte Bitmap ab jetzt zeichnen
  1217.  
  1218.         move.l    d0,a0            ;Adresse ermitteln
  1219.         addq.b    #1,ebm_Lock(a0)
  1220.         move.l    ebm_Dest(a0),CURRENTA5(a4)
  1221.  
  1222.         move.l    (sp)+,a6
  1223.         clr.w    DontPause        ;Darf wieder angehalten werden
  1224.         bra    Periodic6569
  1225.  
  1226. ; Amiga: Chunky-BitMap in Planar konvertieren
  1227. AmigaVBlank    move.w    #-1,DontPause        ;Nicht hier anhalten
  1228.         movem.l    a4-a6,-(sp)
  1229.  
  1230.         tst.w    MustWaitForC2P(pc)    ;Ggf. erst auf c2p4 warten
  1231.         beq    1$
  1232.         move.l    _SysBase,a6
  1233.         move.l    GfxSet,d0
  1234.         JSRLIB    Wait
  1235.  
  1236. 1$        move.l    InvisibleMap,a2        ;Neue Konvertierung starten
  1237.         move.l    ComparisonBuf,a3
  1238.         move.l    TheRastPort,a4
  1239.         move.l    rp_BitMap(a4),a4
  1240.         lea    bm_Planes(a4),a4
  1241.         move.l    CPUTask,a5
  1242.         move.l    GfxSet,d0
  1243.         jsr    _c2p4
  1244.  
  1245.         movem.l    (sp)+,a4-a6
  1246.         move.l    InvisibleMap,CURRENTA5(a4)
  1247.         move.w    #-1,MustWaitForC2P
  1248.         clr.w    DontPause        ;Darf wieder angehalten werden
  1249.         bra    Periodic6569
  1250.  
  1251. ; Picasso: Nichts
  1252. PicassoVBlank    move.w    #-1,DontPause        ;Nicht hier anhalten
  1253.         move.l    a6,-(sp)
  1254.         move.l    _VilIntuiBase(pc),a6
  1255.  
  1256.         move.l    TheScreen,a0
  1257.         jsr    UnLockVillageScreen(a6)
  1258.  
  1259.         move.l    TheScreen,a0        ;Vorher unsichtbare Bitmap
  1260.         move.l    InvBufNum,d0        ;darstellen
  1261.         jsr    VillageSetDisplayBuf(a6)
  1262.  
  1263.         eor.l    #1,InvBufNum        ;Puffer wechseln
  1264.         move.l    TheScreen,a0
  1265.         jsr    LockVillageScreen(a6)
  1266.         move.l    TheScreen,a0        ;Adresse ermitteln
  1267.         move.l    InvBufNum,d0
  1268.         jsr    VillageGetBufAddr(a6)
  1269.         move.l    d0,CURRENTA5(a4)
  1270.  
  1271.         move.l    (sp)+,a6
  1272.         clr.w    DontPause        ;Darf wieder angehalten werden
  1273.         bra    Periodic6569
  1274.  
  1275. *
  1276. * Aktuelle Rasterzeile holen
  1277. *
  1278.  
  1279.         CNOP    0,4
  1280. Periodic6569    lea    Registers,a4
  1281.         move.w    CURRENTRASTER(a4),d7
  1282.  
  1283. *
  1284. * Rasterzähler erhöhen (muß hier geschehen, damit bei einem Raster-IRQ
  1285. *  der Wert des Rasterzählers mit der IRQ-Zeile übereinstimmt)
  1286. *
  1287.  
  1288.         addq.w    #1,d7
  1289.         move.w    d7,CURRENTRASTER(a4)
  1290.         cmp.w    #TotalRasters,d7    ;Bildende erreicht?
  1291.         beq    VICVBlank
  1292.  
  1293. *
  1294. * Raster-IRQ auslösen, wenn Vergeichswert erreicht
  1295. *
  1296.  
  1297.         cmp.w    IRQRASTER(a4),d7    ;IRQ-Zeile erreicht?
  1298.         bne    NoRasterIRQ
  1299.         or.b    #$01,IRQFLAG(a4)    ;Ja, IRST-Bit setzen
  1300.         btst    #0,IRQMASK(a4)        ;Raster-IRQ erlaubt?
  1301.         beq    NoRasterIRQ
  1302.         or.b    #$80,IRQFLAG(a4)    ;Ja, IRQ-Bit setzen
  1303.         st.b    IntIsVICIRQ        ;Und Interrupt auslösen
  1304. NoRasterIRQ
  1305.  
  1306. *
  1307. * Neue Anzahl CPU-Zyklen setzen
  1308. *
  1309.  
  1310.         move.w    NormalCycles,CyclesLeft
  1311.  
  1312. *
  1313. * Innerhalb des sichtbaren Bereichs?
  1314. *
  1315.  
  1316.         cmp.w    #FirstDispLine,d7
  1317.         blo    VICNop
  1318.         cmp.w    #LastDispLine,d7
  1319.         bhi    VICNop
  1320.  
  1321. *
  1322. * Zeiger in Bildschirmspeicher nach a5 holen
  1323. *
  1324.  
  1325.         cmp.w    #STYP_AMIGA,ScreenType
  1326.         bne    1$
  1327.         move.l    CURRENTA5(a4),a5    ;Amiga: In die Chunky-Map schreiben
  1328.         bra    2$
  1329. 1$        lea    LineStore,a5        ;EGS/Picasso: In LineStore schreiben
  1330. 2$
  1331.  
  1332. *
  1333. * Bei abgeschaltetem Bildschirm nur Rahmen zeichnen
  1334. *
  1335.  
  1336.         tst.b    SCREENOFF(a4)
  1337.         bne    TBBorderDraw
  1338.  
  1339. *
  1340. * VC-Zähler setzen
  1341. *
  1342.  
  1343.         move.w    VCBASE(a4),VCCOUNT(a4)
  1344.  
  1345. *
  1346. * "Bad Lines"-Videomatrixzugriff:
  1347. * 40 Bytes aus Videomatrix und Farb-RAM lesen und zwischenspeichern
  1348. *
  1349.  
  1350.         cmp.w    #FirstDMALine,d7 ;Innerhalb des DMA-Bereiches?
  1351.         blo    NoBadLine
  1352.         cmp.w    #LastDMALine,d7
  1353.         bhi    NoBadLine
  1354.  
  1355.         move.b    d7,d0        ;Ja, stimmen die unteren Bits
  1356.         and.b    #7,d0        ;der Rasterzeile mit dem Y-Scroll
  1357.         cmp.b    YSCROLL+1(a4),d0 ;überein?
  1358.         bne    NoBadLine
  1359.  
  1360. IsBadLine    move.w    VCCOUNT(a4),d2    ;d2: VC Videomatrix-Zähler
  1361.  
  1362.         move.l    MATRIXBASE(a4),a0 ;Videomatrixbasis holen
  1363.         add.w    d2,a0        ;Videomatrixzähler dazunehmen
  1364.  
  1365.         move.l    TheColor(pc),a2    ;Zeiger auf Farb-RAM holen
  1366.         add.w    d2,a2        ;Videomatrixzähler dazunehmen
  1367.  
  1368.         lea    MatrixLine,a1    ;Videomatrix- und Farb-RAM-Zeile lesen
  1369.         lea    ColorLine,a3
  1370.         moveq    #40/4-1,d0    ;Jeweils 40 Byte kopieren
  1371. 1$        move.l    (a0)+,(a1)+
  1372.         move.l    (a2)+,(a3)+
  1373.         dbra    d0,1$
  1374.  
  1375.         clr.w    RC(a4)        ;RC zurücksetzen
  1376.         clr.b    DISPLAYOFF(a4)    ;Darstellung anschalten
  1377.  
  1378.         move.w    BadLineCycles,CyclesLeft ;Andere Anzahl Zyklen
  1379. NoBadLine
  1380.  
  1381. *
  1382. * Oberen und unteren Rahmen handhaben
  1383. *
  1384.  
  1385.         cmp.w    DYSTOP(a4),d7    ;Unteres Ende des Fensters erreicht
  1386.         bne    1$        ; -> Rahmen einschalten
  1387.         st.b    BORDERON(a4)
  1388.         bra    TBBorderDraw
  1389.  
  1390. 1$        cmp.w    DYSTART(a4),d7    ;Oberes Ende des Fensters erreicht
  1391.         bne    TBBorderDone    ; -> Rahmen abschalten
  1392.         clr.b    BORDERON(a4)
  1393.         bra    TBNoBorder
  1394.  
  1395. TBBorderDone    tst.b    BORDERON(a4)    ;Rahmen an?
  1396.         beq    TBNoBorder
  1397.  
  1398. TBBorderDraw    move.l    CURRENTA5(a4),a0 ;Ja, Rahmen malen. Und zwar in jedem
  1399.                     ; Fall direkt in die Bitmap schreiben
  1400.                     ; (kein Umweg über LineStore)
  1401.         move.b    $20(a4),d0    ;Rahmenfarbe
  1402.         lsl.w    #8,d0
  1403.         move.b    $20(a4),d0    ;Nochmaliger Zugriff auf $20(a4) ist
  1404.         move.w    d0,d1        ; schneller als der Umweg über ein
  1405.         swap    d0        ; Datenregister
  1406.         move.w    d1,d0
  1407.         move.w    #DisplayX/4-1,d1
  1408. 1$        move.l    d0,(a0)+
  1409.         dbra    d1,1$
  1410.         bra    VICIncA5    ;Sonst nix
  1411. TBNoBorder
  1412.  
  1413. *
  1414. * Inhalt des Fensters: Darstellung eingeschaltet?
  1415. *
  1416.  
  1417.         lea    Col40XStart(a5),a1
  1418.         add.w    XSCROLL(a4),a1    ;a1: Ziel in Bildschirmspeicher
  1419.         lea    MatrixLine,a2    ;a2: Zeichencodes
  1420.         lea    ColorLine,a3    ;a3: Farbcodes
  1421.  
  1422.         tst.b    DISPLAYOFF(a4)    ;$3FFF darstellen?
  1423.         bne    Show3FFF
  1424.  
  1425.         move.l    DisplayProc,a0    ;Nein, Routine entsprechend
  1426.         jmp    (a0)        ;dem Darstellungsmodus anspringen
  1427.  
  1428. *
  1429. * Standard-Text: Zeichendaten holen und darstellen
  1430. *
  1431.  
  1432. TextStd        add.w    #40,VCCOUNT(a4)    ;VC erhöhen (wird nicht verwendet)
  1433.  
  1434.         move.l    CHARBASE(a4),a0    ;a0: Zeichengeneratorbasis
  1435.         add.w    RC(a4),a0    ;RC dazunehmen
  1436.  
  1437.         move.b    $21(a4),d3    ;d3.l: Hintergrundfarbe
  1438.         lsl.w    #8,d3        ;Für OnlyBack auf Langwort bringen
  1439.         move.b    $21(a4),d3
  1440.         move.w    d3,d0
  1441.         swap    d3
  1442.         move.w    d0,d3
  1443.  
  1444.         move.l    d3,Col40XStart(a5) ;Hintergrund, wenn X-Scroll>0
  1445.         move.l    d3,Col40XStart+4(a5)
  1446.  
  1447. ; Schleife für 40 Zeichen
  1448.         moveq    #39,d1        ;d1: Zeichenzähler
  1449.         moveq    #0,d0
  1450. CharLoop    move.b    (a2)+,d0    ;Zeichencode lesen
  1451.         move.b    (a3)+,d2    ;d2: Zeichenfarbe
  1452.         move.b    (a0,d0.w*8),d0    ;Zeichendaten lesen
  1453.         beq    OnlyBack
  1454.  
  1455. ; 8 Pixel konvertieren
  1456.         add.b    d0,d0
  1457.         bcc    11$
  1458.         move.b    d2,(a1)+
  1459.         bra    12$
  1460. 11$        move.b    d3,(a1)+
  1461.  
  1462. 12$        add.b    d0,d0
  1463.         bcc    21$
  1464.         move.b    d2,(a1)+
  1465.         bra    22$
  1466. 21$        move.b    d3,(a1)+
  1467.  
  1468. 22$        add.b    d0,d0
  1469.         bcc    31$
  1470.         move.b    d2,(a1)+
  1471.         bra    32$
  1472. 31$        move.b    d3,(a1)+
  1473.  
  1474. 32$        add.b    d0,d0
  1475.         bcc    41$
  1476.         move.b    d2,(a1)+
  1477.         bra    42$
  1478. 41$        move.b    d3,(a1)+
  1479.  
  1480. 42$        add.b    d0,d0
  1481.         bcc    51$
  1482.         move.b    d2,(a1)+
  1483.         bra    52$
  1484. 51$        move.b    d3,(a1)+
  1485.  
  1486. 52$        add.b    d0,d0
  1487.         bcc    61$
  1488.         move.b    d2,(a1)+
  1489.         bra    62$
  1490. 61$        move.b    d3,(a1)+
  1491.  
  1492. 62$        add.b    d0,d0
  1493.         bcc    71$
  1494.         move.b    d2,(a1)+
  1495.         bra    72$
  1496. 71$        move.b    d3,(a1)+
  1497.  
  1498. 72$        add.b    d0,d0
  1499.         bcc    81$
  1500.         move.b    d2,(a1)+
  1501.         bra    82$
  1502. 81$        move.b    d3,(a1)+
  1503.  
  1504. 82$        dbra    d1,CharLoop
  1505.         bra    DoSprites
  1506.  
  1507. ; Nur Hintergrund
  1508. OnlyBack    move.l    d3,(a1)+
  1509.         move.l    d3,(a1)+
  1510.         dbra    d1,CharLoop
  1511.         bra    DoSprites
  1512.  
  1513. *
  1514. * Multicolor-Text: Zeichendaten holen und darstellen
  1515. *
  1516.  
  1517. TextMulti    add.w    #40,VCCOUNT(a4)    ;VC erhöhen (wird nicht verwendet)
  1518.  
  1519.         move.l    CHARBASE(a4),a0    ;a0: Zeichengeneratorbasis
  1520.         add.w    RC(a4),a0    ;RC dazunehmen
  1521.  
  1522.         move.b    $21(a4),d3    ;d3.w: Farbe 0
  1523.         lsl.w    #8,d3
  1524.         move.b    $21(a4),d3
  1525.  
  1526.         move.b    $22(a4),d4    ;d4.w: Farbe 1
  1527.         lsl.w    #8,d4
  1528.         move.b    $22(a4),d4
  1529.  
  1530.         move.b    $23(a4),d5    ;d5.w: Farbe 2
  1531.         lsl.w    #8,d5
  1532.         move.b    $23(a4),d5
  1533.  
  1534.         move.w    d3,Col40XStart(a5) ;Hintergrund, wenn X-Scroll>0
  1535.         move.w    d3,Col40XStart+2(a5)
  1536.         move.w    d3,Col40XStart+4(a5)
  1537.         move.w    d3,Col40XStart+6(a5)
  1538.  
  1539. ; Schleife für 40 Zeichen
  1540.         moveq    #39,d1        ;d1: Zeichenzähler
  1541.         moveq    #0,d0
  1542. CharMLoop    move.b    (a2)+,d0    ;Zeichencode lesen
  1543.         move.b    (a3)+,d2    ;d2: Farbnibble
  1544.         move.b    (a0,d0.w*8),d0    ;Zeichendaten lesen
  1545.         bclr    #3,d2        ;Standard oder Multi?
  1546.         beq    StdInMulti
  1547.  
  1548. ; Multicolor: 4 Pixel konvertieren
  1549.         add.b    d0,d0
  1550.         bcc    11$
  1551.         add.b    d0,d0
  1552.         bcc    12$
  1553.         move.b    d2,(a1)+    ;11
  1554.         move.b    d2,(a1)+
  1555.         bra    20$
  1556. 12$        move.w    d5,(a1)+    ;10
  1557.         bra    20$
  1558. 11$        add.b    d0,d0
  1559.         bcc    13$
  1560.         move.w    d4,(a1)+    ;01
  1561.         bra    20$
  1562. 13$        move.w    d3,(a1)+    ;00
  1563.  
  1564. 20$        add.b    d0,d0
  1565.         bcc    21$
  1566.         add.b    d0,d0
  1567.         bcc    22$
  1568.         move.b    d2,(a1)+
  1569.         move.b    d2,(a1)+
  1570.         bra    30$
  1571. 22$        move.w    d5,(a1)+
  1572.         bra    30$
  1573. 21$        add.b    d0,d0
  1574.         bcc    23$
  1575.         move.w    d4,(a1)+
  1576.         bra    30$
  1577. 23$        move.w    d3,(a1)+
  1578.  
  1579. 30$        add.b    d0,d0
  1580.         bcc    31$
  1581.         add.b    d0,d0
  1582.         bcc    32$
  1583.         move.b    d2,(a1)+
  1584.         move.b    d2,(a1)+
  1585.         bra    40$
  1586. 32$        move.w    d5,(a1)+
  1587.         bra    40$
  1588. 31$        add.b    d0,d0
  1589.         bcc    33$
  1590.         move.w    d4,(a1)+
  1591.         bra    40$
  1592. 33$        move.w    d3,(a1)+
  1593.  
  1594. 40$        add.b    d0,d0
  1595.         bcc    41$
  1596.         add.b    d0,d0
  1597.         bcc    42$
  1598.         move.b    d2,(a1)+
  1599.         move.b    d2,(a1)+
  1600.         bra    50$
  1601. 42$        move.w    d5,(a1)+
  1602.         bra    50$
  1603. 41$        add.b    d0,d0
  1604.         bcc    43$
  1605.         move.w    d4,(a1)+
  1606.         bra    50$
  1607. 43$        move.w    d3,(a1)+
  1608.  
  1609. 50$        dbra    d1,CharMLoop
  1610.         bra    DoSprites
  1611.  
  1612. ; Standard: 8 Pixel konvertieren
  1613. StdInMulti    add.b    d0,d0
  1614.         bcc    11$
  1615.         move.b    d2,(a1)+
  1616.         bra    12$
  1617. 11$        move.b    d3,(a1)+
  1618.  
  1619. 12$        add.b    d0,d0
  1620.         bcc    21$
  1621.         move.b    d2,(a1)+
  1622.         bra    22$
  1623. 21$        move.b    d3,(a1)+
  1624.  
  1625. 22$        add.b    d0,d0
  1626.         bcc    31$
  1627.         move.b    d2,(a1)+
  1628.         bra    32$
  1629. 31$        move.b    d3,(a1)+
  1630.  
  1631. 32$        add.b    d0,d0
  1632.         bcc    41$
  1633.         move.b    d2,(a1)+
  1634.         bra    42$
  1635. 41$        move.b    d3,(a1)+
  1636.  
  1637. 42$        add.b    d0,d0
  1638.         bcc    51$
  1639.         move.b    d2,(a1)+
  1640.         bra    52$
  1641. 51$        move.b    d3,(a1)+
  1642.  
  1643. 52$        add.b    d0,d0
  1644.         bcc    61$
  1645.         move.b    d2,(a1)+
  1646.         bra    62$
  1647. 61$        move.b    d3,(a1)+
  1648.  
  1649. 62$        add.b    d0,d0
  1650.         bcc    71$
  1651.         move.b    d2,(a1)+
  1652.         bra    72$
  1653. 71$        move.b    d3,(a1)+
  1654.  
  1655. 72$        add.b    d0,d0
  1656.         bcc    81$
  1657.         move.b    d2,(a1)+
  1658.         bra    82$
  1659. 81$        move.b    d3,(a1)+
  1660.  
  1661. 82$        dbra    d1,CharMLoop
  1662.         bra    DoSprites
  1663.  
  1664. *
  1665. * Extended Color Mode: Grafikdaten holen und darstellen
  1666. *
  1667.  
  1668. TextECM        add.w    #40,VCCOUNT(a4)    ;VC erhöhen (wird nicht verwendet)
  1669.  
  1670.         move.l    CHARBASE(a4),a0    ;a0: Zeichengeneratorbasis
  1671.         add.w    RC(a4),a0    ;RC dazunehmen
  1672.  
  1673.         move.b    $21(a4),d3    ;d3: Hintergrund 0
  1674.         move.b    $22(a4),d4    ;d4: Hintergrund 1
  1675.         move.b    $23(a4),d5    ;d5: Hintergrund 2
  1676.         move.b    $24(a4),d6    ;d6: Hintergrund 3
  1677.  
  1678.         move.b    LASTBKGD(a4),d0    ;Letzter Hintergrund, wenn X-Scroll>0
  1679.         lsl.w    #8,d0
  1680.         move.b    LASTBKGD(a4),d0
  1681.  
  1682.         move.w    d0,Col40XStart(a5)
  1683.         move.w    d0,Col40XStart+2(a5)
  1684.         move.w    d0,Col40XStart+4(a5)
  1685.         move.w    d0,Col40XStart+6(a5)
  1686.  
  1687. ; Schleife für 40 Zeichen
  1688.         move.w    d7,-(sp)    ;d7: Aktuelle Hintergrundfarbe
  1689.         moveq    #39,d1        ;d1: Zeichenzähler
  1690.         moveq    #0,d0
  1691. CharELoop    move.b    (a2)+,d0    ;Zeichencode lesen
  1692.         move.b    (a3)+,d2    ;d2: Farbnibble
  1693.         bclr    #7,d0
  1694.         bne    1$
  1695.         bclr    #6,d0
  1696.         bne    2$
  1697.         move.b    d3,d7        ;00: Hintergrund 0
  1698.         bra    4$
  1699. 2$        move.b    d4,d7        ;01: Hintergrund 1
  1700.         bra    4$
  1701. 1$        bclr    #6,d0
  1702.         bne    3$
  1703.         move.b    d5,d7        ;10: Hintergrund 2
  1704.         bra    4$
  1705. 3$        move.b    d6,d7        ;11: Hintergrund 3
  1706. 4$        move.b    (a0,d0.w*8),d0    ;Zeichendaten lesen
  1707.  
  1708. ; 8 Pixel konvertieren
  1709.         add.b    d0,d0
  1710.         bcc    11$
  1711.         move.b    d2,(a1)+
  1712.         bra    12$
  1713. 11$        move.b    d7,(a1)+
  1714.  
  1715. 12$        add.b    d0,d0
  1716.         bcc    21$
  1717.         move.b    d2,(a1)+
  1718.         bra    22$
  1719. 21$        move.b    d7,(a1)+
  1720.  
  1721. 22$        add.b    d0,d0
  1722.         bcc    31$
  1723.         move.b    d2,(a1)+
  1724.         bra    32$
  1725. 31$        move.b    d7,(a1)+
  1726.  
  1727. 32$        add.b    d0,d0
  1728.         bcc    41$
  1729.         move.b    d2,(a1)+
  1730.         bra    42$
  1731. 41$        move.b    d7,(a1)+
  1732.  
  1733. 42$        add.b    d0,d0
  1734.         bcc    51$
  1735.         move.b    d2,(a1)+
  1736.         bra    52$
  1737. 51$        move.b    d7,(a1)+
  1738.  
  1739. 52$        add.b    d0,d0
  1740.         bcc    61$
  1741.         move.b    d2,(a1)+
  1742.         bra    62$
  1743. 61$        move.b    d7,(a1)+
  1744.  
  1745. 62$        add.b    d0,d0
  1746.         bcc    71$
  1747.         move.b    d2,(a1)+
  1748.         bra    72$
  1749. 71$        move.b    d7,(a1)+
  1750.  
  1751. 72$        add.b    d0,d0
  1752.         bcc    81$
  1753.         move.b    d2,(a1)+
  1754.         bra    82$
  1755. 81$        move.b    d7,(a1)+
  1756.  
  1757. 82$        dbra    d1,CharELoop
  1758.  
  1759.         move.b    d7,LASTBKGD(a4)    ;Letzte Hintergrundfarbe merken
  1760.         move.w    (sp)+,d7
  1761.         bra    DoSprites
  1762.  
  1763. *
  1764. * Standard-BitMap: Grafikdaten holen und darstellen
  1765. *
  1766.  
  1767. BitMapStd    move.l    BITMAPBASE(a4),a0 ;a0: Bitmap-Basis
  1768.         move.w    VCCOUNT(a4),d0    ;VC holen
  1769.         lsl.w    #3,d0        ;*8
  1770.         add.w    RC(a4),d0    ;RC dazunehmen
  1771.         add.w    d0,a0        ;und zur Bitmap-Basis dazunehmen
  1772.  
  1773.         add.w    #40,VCCOUNT(a4)    ;VC erhöhen
  1774.  
  1775.         move.b    LASTBKGD(a4),d0    ;Letzter Hintergrund, wenn X-Scroll>0
  1776.         lsl.w    #8,d0
  1777.         move.b    LASTBKGD(a4),d0
  1778.  
  1779.         move.w    d0,Col40XStart(a5)
  1780.         move.w    d0,Col40XStart+2(a5)
  1781.         move.w    d0,Col40XStart+4(a5)
  1782.         move.w    d0,Col40XStart+6(a5)
  1783.  
  1784. ; Schleife für 40 Bytes
  1785.         moveq    #39,d1        ;d1: Zeichenzähler
  1786. BitMapLoop    move.b    (a2)+,d2    ;Farbe holen
  1787.         move.b    d2,d3        ;d3: Hintergrundfarbe
  1788.         move.b    (a0),d0        ;Byte holen
  1789.         lsr.b    #4,d2        ;d2: Vordergrundfarbe
  1790.  
  1791. ; 8 Pixel konvertieren
  1792.         add.b    d0,d0
  1793.         bcc    11$
  1794.         move.b    d2,(a1)+
  1795.         bra    12$
  1796. 11$        move.b    d3,(a1)+
  1797.  
  1798. 12$        add.b    d0,d0
  1799.         bcc    21$
  1800.         move.b    d2,(a1)+
  1801.         bra    22$
  1802. 21$        move.b    d3,(a1)+
  1803.  
  1804. 22$        add.b    d0,d0
  1805.         bcc    31$
  1806.         move.b    d2,(a1)+
  1807.         bra    32$
  1808. 31$        move.b    d3,(a1)+
  1809.  
  1810. 32$        add.b    d0,d0
  1811.         bcc    41$
  1812.         move.b    d2,(a1)+
  1813.         bra    42$
  1814. 41$        move.b    d3,(a1)+
  1815.  
  1816. 42$        add.b    d0,d0
  1817.         bcc    51$
  1818.         move.b    d2,(a1)+
  1819.         bra    52$
  1820. 51$        move.b    d3,(a1)+
  1821.  
  1822. 52$        add.b    d0,d0
  1823.         bcc    61$
  1824.         move.b    d2,(a1)+
  1825.         bra    62$
  1826. 61$        move.b    d3,(a1)+
  1827.  
  1828. 62$        add.b    d0,d0
  1829.         bcc    71$
  1830.         move.b    d2,(a1)+
  1831.         bra    72$
  1832. 71$        move.b    d3,(a1)+
  1833.  
  1834. 72$        add.b    d0,d0
  1835.         bcc    81$
  1836.         move.b    d2,(a1)+
  1837.         bra    82$
  1838. 81$        move.b    d3,(a1)+
  1839.  
  1840. 82$        addq.l    #8,a0        ;Quellzeiger erhöhen
  1841.         dbra    d1,BitMapLoop
  1842.  
  1843.         move.b    d3,LASTBKGD(a4)    ;Letzte Hintergrundfarbe merken
  1844.         bra    DoSprites
  1845.  
  1846. *
  1847. * Multicolor-Bitmap: Grafikdaten holen und darstellen
  1848. *
  1849.  
  1850. BitMapMulti    move.l    BITMAPBASE(a4),a0 ;a0: Bitmap-Basis
  1851.         move.w    VCCOUNT(a4),d0    ;VC holen
  1852.         lsl.w    #3,d0        ;*8
  1853.         add.w    RC(a4),d0    ;RC dazunehmen
  1854.         add.w    d0,a0        ;und zur Bitmap-Basis dazunehmen
  1855.  
  1856.         add.w    #40,VCCOUNT(a4)    ;VC erhöhen
  1857.  
  1858.         move.b    $21(a4),d5    ;d5.w: Farbe 0
  1859.         lsl.w    #8,d5
  1860.         move.b    $21(a4),d5
  1861.  
  1862.         move.w    d5,Col40XStart(a5) ;Hintergrund, wenn X-Scroll>0
  1863.         move.w    d5,Col40XStart+2(a5)
  1864.         move.w    d5,Col40XStart+4(a5)
  1865.         move.w    d5,Col40XStart+6(a5)
  1866.  
  1867. ; Schleife für 40 Bytes
  1868.         moveq    #39,d1
  1869. BitMapMLoop    move.b    (a2)+,d2    ;Farbe 1/2 holen
  1870.         move.b    d2,d3        ;d3.b: Farbe 2
  1871.         move.b    (a0),d0        ;Byte holen
  1872.         lsr.b    #4,d2        ;d2.b: Farbe 1
  1873.         move.b    (a3)+,d4    ;d4.b: Farbe 3
  1874.  
  1875. ; 4 Pixel konvertieren
  1876.         add.b    d0,d0
  1877.         bcc    11$
  1878.         add.b    d0,d0
  1879.         bcc    12$
  1880.         move.b    d4,(a1)+    ;11
  1881.         move.b    d4,(a1)+
  1882.         bra    20$
  1883. 12$        move.b    d3,(a1)+    ;10
  1884.         move.b    d3,(a1)+
  1885.         bra    20$
  1886. 11$        add.b    d0,d0
  1887.         bcc    13$
  1888.         move.b    d2,(a1)+    ;01
  1889.         move.b    d2,(a1)+
  1890.         bra    20$
  1891. 13$        move.w    d5,(a1)+    ;00
  1892.  
  1893. 20$        add.b    d0,d0
  1894.         bcc    21$
  1895.         add.b    d0,d0
  1896.         bcc    22$
  1897.         move.b    d4,(a1)+
  1898.         move.b    d4,(a1)+
  1899.         bra    30$
  1900. 22$        move.b    d3,(a1)+
  1901.         move.b    d3,(a1)+
  1902.         bra    30$
  1903. 21$        add.b    d0,d0
  1904.         bcc    23$
  1905.         move.b    d2,(a1)+
  1906.         move.b    d2,(a1)+
  1907.         bra    30$
  1908. 23$        move.w    d5,(a1)+
  1909.  
  1910. 30$        add.b    d0,d0
  1911.         bcc    31$
  1912.         add.b    d0,d0
  1913.         bcc    32$
  1914.         move.b    d4,(a1)+
  1915.         move.b    d4,(a1)+
  1916.         bra    40$
  1917. 32$        move.b    d3,(a1)+
  1918.         move.b    d3,(a1)+
  1919.         bra    40$
  1920. 31$        add.b    d0,d0
  1921.         bcc    33$
  1922.         move.b    d2,(a1)+
  1923.         move.b    d2,(a1)+
  1924.         bra    40$
  1925. 33$        move.w    d5,(a1)+
  1926.  
  1927. 40$        add.b    d0,d0
  1928.         bcc    41$
  1929.         add.b    d0,d0
  1930.         bcc    42$
  1931.         move.b    d4,(a1)+
  1932.         move.b    d4,(a1)+
  1933.         bra    50$
  1934. 42$        move.b    d3,(a1)+
  1935.         move.b    d3,(a1)+
  1936.         bra    50$
  1937. 41$        add.b    d0,d0
  1938.         bcc    43$
  1939.         move.b    d2,(a1)+
  1940.         move.b    d2,(a1)+
  1941.         bra    50$
  1942. 43$        move.w    d5,(a1)+
  1943.  
  1944. 50$        addq.l    #8,a0        ;Quellzeiger erhöhen
  1945.         dbra    d1,BitMapMLoop
  1946.         bra    DoSprites
  1947.  
  1948. *
  1949. * Ungültiger Darstellungsmodus: Schwarzen Bildschirm anzeigen
  1950. *
  1951.  
  1952. BlackScreen    add.w    #40,VCCOUNT(a4)    ;VC erhöhen
  1953.  
  1954.         moveq    #39,d0        ;40 Zeichen schwarz
  1955. 1$        clr.l    (a1)+
  1956.         clr.l    (a1)+
  1957.         dbra    d0,1$
  1958.         bra    DoSprites
  1959.  
  1960. *
  1961. * $3FFF darstellen
  1962. *
  1963.  
  1964. Show3FFF    move.b    $21(a4),d3    ;d3.w: Hintergrundfarbe
  1965.         lsl.w    #8,d3
  1966.         move.b    $21(a4),d3
  1967.  
  1968.         move.w    d3,Col40XStart(a5) ;Hintergrund, wenn X-Scroll>0
  1969.         move.w    d3,Col40XStart+2(a5)
  1970.         move.w    d3,Col40XStart+4(a5)
  1971.         move.w    d3,Col40XStart+6(a5)
  1972.  
  1973.         btst    #6,CTRL1(a4)
  1974.         bne    11$
  1975.         move.w    #$3fff,d0    ;Byte bei $3FFF lesen
  1976.         bra    12$
  1977. 11$        move.w    #$39ff,d0    ;ECM: Byte bei $39FF lesen
  1978. 12$        GetPhysical
  1979.         move.b    (a0),d0        ;Byte lesen
  1980.  
  1981. ; 4 Pixel nach d1 konvertieren, 0: Hintergrund, 1: schwarz
  1982.         moveq    #0,d1
  1983.         add.b    d0,d0
  1984.         bcs    1$
  1985.         move.b    d3,d1
  1986. 1$        lsl.w    #8,d1
  1987.         add.b    d0,d0
  1988.         bcs    2$
  1989.         move.b    d3,d1
  1990. 2$        lsl.l    #8,d1
  1991.         add.b    d0,d0
  1992.         bcs    3$
  1993.         move.b    d3,d1
  1994. 3$        lsl.l    #8,d1
  1995.         add.b    d0,d0
  1996.         bcs    4$
  1997.         move.b    d3,d1
  1998. 4$
  1999.  
  2000. ; 4 Pixel nach d2 konvertieren
  2001.         moveq    #0,d2
  2002.         add.b    d0,d0
  2003.         bcs    5$
  2004.         move.b    d3,d2
  2005. 5$        lsl.w    #8,d2
  2006.         add.b    d0,d0
  2007.         bcs    6$
  2008.         move.b    d3,d2
  2009. 6$        lsl.l    #8,d2
  2010.         add.b    d0,d0
  2011.         bcs    7$
  2012.         move.b    d3,d2
  2013. 7$        lsl.l    #8,d2
  2014.         add.b    d0,d0
  2015.         bcs    8$
  2016.         move.b    d3,d2
  2017. 8$
  2018.  
  2019. ; Zeile schreiben
  2020.         moveq    #39,d0        ;d0: Bytezähler
  2021. Loop3FFF    move.l    d1,(a1)+
  2022.         move.l    d2,(a1)+
  2023.         dbra    d0,Loop3FFF
  2024.  
  2025. *
  2026. * Sprites
  2027. *
  2028.  
  2029. DoSprites    tst.b    SPRITEON(a4)    ;Ist überhaupt ein Sprite z.Z. sichtbar?
  2030.         beq    DrawLRBorder    ;Nein, dann schenken wir uns das
  2031.  
  2032. ; Kollisions-Puffer löschen
  2033.         lea    SprCollBuf,a0
  2034.         moveq    #DisplayX/4-1,d0
  2035. 5$        clr.l    (a0)+
  2036.         dbra    d0,5$
  2037.  
  2038.         move.b    $25(a4),d3    ;d3.l: Multicolor #0
  2039.         lsl.w    #8,d3
  2040.         move.b    $25(a4),d3
  2041.         move.w    d3,d0
  2042.         swap    d3
  2043.         move.w    d0,d3
  2044.  
  2045.         move.b    $26(a4),d4    ;d4.l: Multicolor #1
  2046.         lsl.w    #8,d4
  2047.         move.b    $26(a4),d4
  2048.         move.w    d4,d0
  2049.         swap    d4
  2050.         move.w    d0,d4
  2051.  
  2052. ; Sprites malen
  2053.         move.l    d7,-(sp)
  2054.         DoSprite 7
  2055.         DoSprite 6
  2056.         DoSprite 5
  2057.         DoSprite 4
  2058.         DoSprite 3
  2059.         DoSprite 2
  2060.         DoSprite 1
  2061.         DoSprite 0
  2062.         move.l    (sp)+,d7
  2063.  
  2064. ; Kollisions-Puffer auswerten
  2065.         lea    SprCollBuf,a0
  2066.         lea    SprCollTab,a1
  2067.         moveq    #0,d0
  2068.         move.w    #DisplayX-1,d2
  2069. 1$        move.b    (a0)+,d0    ;Byte aus Puffer holen
  2070.         tst.b    (a1,d0.w)    ;Entspricht die Bitkombination einer
  2071.         bne    2$        ; Kollision?
  2072.         dbra    d2,1$        ;Nein, weitertesten
  2073.         bra    4$
  2074.  
  2075. 2$        move.b    CLXSPR(a4),d1    ;Ja, Kollision erkannt
  2076.         or.b    d0,CLXSPR(a4)    ;Bits im Kollisionsregister setzen
  2077.         tst.b    d1        ;Wenn bereits Kollisionen stattgefunden
  2078.         bne    3$        ; haben, keinen IRQ mehr auslösen
  2079.         or.b    #$04,IRQFLAG(a4) ;IMMC-Bit setzen
  2080.         btst    #2,IRQMASK(a4)    ;IRQ erlaubt?
  2081.         beq    3$
  2082.         or.b    #$80,IRQFLAG(a4) ;Ja, IRQ-Bit setzen
  2083.         st.b    IntIsVICIRQ    ;Und Interrupt auslösen
  2084. 3$        dbra    d2,1$
  2085. 4$
  2086.  
  2087. *
  2088. * Linken und rechten Rahmen zeichnen
  2089. *
  2090.  
  2091. ; 40-Spalten-Rahmen direkt in die Bitmap
  2092. DrawLRBorder    move.l    CURRENTA5(a4),a0
  2093.         move.b    $20(a4),d0    ;d0.l: Rahmenfarbe
  2094.         lsl.w    #8,d0
  2095.         move.b    $20(a4),d0
  2096.         move.w    d0,d1
  2097.         swap    d0
  2098.         move.w    d1,d0
  2099.  
  2100.         move.l    d0,(a0)+    ;Links: $00..$17
  2101.         move.l    d0,(a0)+
  2102.         move.l    d0,(a0)+
  2103.         move.l    d0,(a0)+
  2104.         move.l    d0,(a0)+
  2105.         move.l    d0,(a0)+
  2106.  
  2107.         lea    Col40XStop-Col40XStart(a0),a0
  2108.         move.l    d0,(a0)+    ;Rechts: $158..$16f
  2109.         move.l    d0,(a0)+
  2110.         move.l    d0,(a0)+
  2111.         move.l    d0,(a0)+
  2112.         move.l    d0,(a0)+
  2113.         move.l    d0,(a0)
  2114.  
  2115. ; 38-Spalten-Rahmen nach (a5) (Puffer oder Bitmap)
  2116.         tst.b    IS38COL(a4)
  2117.         beq    1$
  2118.  
  2119.         lea    Col40XStart(a5),a0
  2120.         move.l    d0,(a0)+    ;Links: $18..$1e
  2121.         move.w    d0,(a0)+
  2122.         move.b    d0,(a0)
  2123.  
  2124.         lea    Col38XStop(a5),a0
  2125.         move.b    d0,(a0)+    ;Rechts: $14f..$157
  2126.         move.l    d0,(a0)+
  2127.         move.l    d0,(a0)+
  2128. 1$
  2129.  
  2130. *
  2131. * Ende einer sichtbaren Zeile: Bei EGS/Picasso Zeile in die Karte schreiben
  2132. * Es wird nur der Bereich zwischen Col40XStart und Col40XStop geschrieben,
  2133. * der Rest ist immer Rahmen und der wird in DrawLRBorder direkt in die
  2134. * Bitmap geschrieben.
  2135. *
  2136.  
  2137. VICNext        cmp.w    #STYP_AMIGA,ScreenType
  2138.         beq    VICIncA5
  2139.         move.l    CURRENTA5(a4),a1
  2140.         lea    Col40XStart(a1),a1
  2141.         lea    LineStore+Col40XStart,a0
  2142.         moveq    #(Col40XStop-Col40XStart)/4-1,d0
  2143. 1$        move.l    (a0)+,(a1)+
  2144.         dbra    d0,1$
  2145.  
  2146. *
  2147. * Zeiger in Bitmap erhöhen
  2148. *
  2149.  
  2150. VICIncA5    moveq    #0,d0
  2151.         move.w    ScreenX,d0
  2152.         add.l    d0,CURRENTA5(a4)
  2153.  
  2154. *
  2155. * RC erhöhen, Darstellung abschalten, wenn gleich 7
  2156. * (braucht nur im sichtbaren Bereich zu geschehen)
  2157. *
  2158.  
  2159.         cmp.w    #7,RC(a4)
  2160.         beq    1$
  2161.         addq.w    #1,RC(a4)
  2162.         bra    2$
  2163. 1$        st.b    DISPLAYOFF(a4)
  2164.         move.w    VCCOUNT(a4),VCBASE(a4)
  2165. 2$
  2166.  
  2167. *
  2168. * MCs erhöhen (muß in jeder Rasterzeile geschehen, damit die Sprites
  2169. *  auch im Overscan-Bereich korrekt dargestellt werden)
  2170. *
  2171.  
  2172. VICNop        lea    SPRITEON(a4),a3
  2173.  
  2174.         move.b    M0Y(a4),d0    ;Y-Koordinate
  2175.         moveq    #0,d6        ;Spritenummer
  2176.         lea    MC0(a4),a2    ;Zeiger auf MC
  2177.         bsr    IncMC
  2178.  
  2179.         move.b    M1Y(a4),d0    ;Y-Koordinate
  2180.         moveq    #1,d6        ;Spritenummer
  2181.         lea    MC1(a4),a2    ;Zeiger auf MC
  2182.         bsr    IncMC
  2183.  
  2184.         move.b    M2Y(a4),d0    ;Y-Koordinate
  2185.         moveq    #2,d6        ;Spritenummer
  2186.         lea    MC2(a4),a2    ;Zeiger auf MC
  2187.         bsr    IncMC
  2188.  
  2189.         move.b    M3Y(a4),d0    ;Y-Koordinate
  2190.         moveq    #3,d6        ;Spritenummer
  2191.         lea    MC3(a4),a2    ;Zeiger auf MC
  2192.         bsr    IncMC
  2193.  
  2194.         move.b    M4Y(a4),d0    ;Y-Koordinate
  2195.         moveq    #4,d6        ;Spritenummer
  2196.         lea    MC4(a4),a2    ;Zeiger auf MC
  2197.         bsr    IncMC
  2198.  
  2199.         move.b    M5Y(a4),d0    ;Y-Koordinate
  2200.         moveq    #5,d6        ;Spritenummer
  2201.         lea    MC5(a4),a2    ;Zeiger auf MC
  2202.         bsr    IncMC
  2203.  
  2204.         move.b    M6Y(a4),d0    ;Y-Koordinate
  2205.         moveq    #6,d6        ;Spritenummer
  2206.         lea    MC6(a4),a2    ;Zeiger auf MC
  2207.         bsr    IncMC
  2208.  
  2209.         move.b    M7Y(a4),d0    ;Y-Koordinate
  2210.         moveq    #7,d6        ;Spritenummer
  2211.         lea    MC7(a4),a2    ;Zeiger auf MC
  2212.         bsr    IncMC
  2213.  
  2214. ; In 6510-Task zurückspringen
  2215.         bra    Peri6569Cont
  2216.  
  2217.  
  2218. **
  2219. ** Spritedatenzähler erhöhen, zurücksetzen wenn nötig
  2220. ** d0.b: Y-Koordinate
  2221. ** d6.l: Spritenummer (0..7)
  2222. ** a2  : Zeiger auf MC
  2223. ** a3  : Zeiger auf SPRITEON
  2224. **
  2225.  
  2226.         CNOP    0,4
  2227. IncMC        btst    d6,SPREN(a4)    ;Sprite angeschaltet?
  2228.         beq    3$
  2229.         cmp.b    d0,d7        ;Ja, Y-Koord. gleich den unteren
  2230.         bne    3$        ; 8 Bit des Rasterzählers?
  2231.         clr.w    (a2)        ;Ja, Zähler zurücksetzen
  2232.         bset    d6,(a3)        ;Und Sprite ab jetzt darstellen
  2233.         rts
  2234.  
  2235. 3$        cmp.w    #60,(a2)    ;MC kleiner als 60?
  2236.         bhs    4$
  2237.         btst    d6,MYE(a4)    ;Ja, Sprite Y-expandiert?
  2238.         beq    1$
  2239.         eor.b    d7,d0        ;Ja, nur erhöhen, wenn Bit 0
  2240.         and.b    #$01,d0        ; der Y-Koordinate gleich Bit 0
  2241.         bne    2$        ; des Rasterzählers ist
  2242. 1$        addq.w    #3,(a2)        ;MC erhöhen
  2243.         subq.w    #2,CyclesLeft    ;2 Zyklen vom 6510 abziehen
  2244.         rts
  2245. 4$        bclr    d6,(a3)        ;MC gleich 60, Sprite nicht mehr darstellen
  2246. 2$        rts
  2247.  
  2248.  
  2249. **
  2250. ** Ein Sprite zeichnen
  2251. ** d2.w: Spritefarbe
  2252. ** d3.l: Multicolor #0
  2253. ** d4.l: Multicolor #1
  2254. ** d5.w: MC
  2255. ** d6.l: Spritenummer (0..7)
  2256. ** d7.b: Spritedatenzeiger
  2257. ** a2  : Zeiger auf X-Koordinate
  2258. **
  2259.  
  2260.         CNOP    0,4
  2261. DrawSprite    btst    d6,SPRITEON(a4)    ;Wird das Sprite dargestellt?
  2262.         beq    SpriteDone
  2263.  
  2264.         moveq    #0,d0        ;Ja, Basisadresse berechnen
  2265.         move.b    d7,d0        ;Spritedatenzeiger
  2266.         lsl.w    #6,d0
  2267.         add.w    d5,d0        ;MC dazunehmen
  2268.         GetPhysical        ;a0: Spritedaten
  2269.  
  2270.         moveq    #0,d5        ;X-Position zusammenbauen
  2271.         move.b    (a2),d5
  2272.         btst    d6,MX8(a4)
  2273.         beq    1$
  2274.         or.w    #$0100,d5    ;d5: Sprite-X-Position
  2275. 1$        cmp.w    #DisplayX-24,d5
  2276.         bhs    SpriteDone
  2277.         move.l    a5,a1
  2278.         add.w    d5,a1        ;a1: Ziel in Bildschirmspeicher
  2279.         lea    SprCollBuf,a2
  2280.         add.w    d5,a2        ;a2: Ziel im Kollisionspuffer
  2281.  
  2282.         btst    d6,MMC(a4)    ;Multicolor?
  2283.         bne    SprMulti
  2284.  
  2285.         btst    d6,MXE(a4)    ;Nein, X-expandiert?
  2286.         bne    SprStdExp
  2287.  
  2288. ; Standard-Sprite: 3 Byte mit je 8 Pixeln konvertieren
  2289.         moveq    #0,d5
  2290.         bset    d6,d5        ;d5: Bitmaske für Kollisionspuffer
  2291.  
  2292.         moveq    #2,d1        ;Bytezähler
  2293. SprLoop        move.b    (a0)+,d0    ;Byte lesen
  2294.         beq    18$        ;Null: Nichts darstellen
  2295.  
  2296.         add.b    d0,d0
  2297.         bcc    11$
  2298.         move.b    d2,(a1)
  2299.         or.b    d5,(a2)
  2300.  
  2301. 11$        add.b    d0,d0
  2302.         bcc    12$
  2303.         move.b    d2,1(a1)
  2304.         or.b    d5,1(a2)
  2305.  
  2306. 12$        add.b    d0,d0
  2307.         bcc    13$
  2308.         move.b    d2,2(a1)
  2309.         or.b    d5,2(a2)
  2310.  
  2311. 13$        add.b    d0,d0
  2312.         bcc    14$
  2313.         move.b    d2,3(a1)
  2314.         or.b    d5,3(a2)
  2315.  
  2316. 14$        add.b    d0,d0
  2317.         bcc    15$
  2318.         move.b    d2,4(a1)
  2319.         or.b    d5,4(a2)
  2320.  
  2321. 15$        add.b    d0,d0
  2322.         bcc    16$
  2323.         move.b    d2,5(a1)
  2324.         or.b    d5,5(a2)
  2325.  
  2326. 16$        add.b    d0,d0
  2327.         bcc    17$
  2328.         move.b    d2,6(a1)
  2329.         or.b    d5,6(a2)
  2330.  
  2331. 17$        add.b    d0,d0
  2332.         bcc    18$
  2333.         move.b    d2,7(a1)
  2334.         or.b    d5,7(a2)
  2335.  
  2336. 18$        addq.l    #8,a1
  2337.         addq.l    #8,a2
  2338.         dbra    d1,SprLoop
  2339. SpriteDone    rts
  2340.  
  2341. ; X-expandiertes Standard-Sprite: 3 Byte mit je 8 Pixeln konvertieren
  2342. SprStdExp    cmp.w    #DisplayX-48,d5    ;Sprite sichtbar?
  2343.         bhs    SpriteDone
  2344.  
  2345.         moveq    #0,d5
  2346.         bset    d6,d5
  2347.         lsl.w    #8,d5
  2348.         bset    d6,d5        ;d5: Bitmaske für Kollisionspuffer
  2349.  
  2350.         moveq    #2,d1        ;Bytezähler
  2351. SprELoop    move.b    (a0)+,d0    ;Byte lesen
  2352.         beq    18$        ;Null: Nichts darstellen
  2353.  
  2354.         add.b    d0,d0
  2355.         bcc    11$
  2356.         move.w    d2,(a1)
  2357.         or.w    d5,(a2)
  2358.  
  2359. 11$        add.b    d0,d0
  2360.         bcc    12$
  2361.         move.w    d2,2(a1)
  2362.         or.w    d5,2(a2)
  2363.  
  2364. 12$        add.b    d0,d0
  2365.         bcc    13$
  2366.         move.w    d2,4(a1)
  2367.         or.w    d5,4(a2)
  2368.  
  2369. 13$        add.b    d0,d0
  2370.         bcc    14$
  2371.         move.w    d2,6(a1)
  2372.         or.w    d5,6(a2)
  2373.  
  2374. 14$        add.b    d0,d0
  2375.         bcc    15$
  2376.         move.w    d2,8(a1)
  2377.         or.w    d5,8(a2)
  2378.  
  2379. 15$        add.b    d0,d0
  2380.         bcc    16$
  2381.         move.w    d2,10(a1)
  2382.         or.w    d5,10(a2)
  2383.  
  2384. 16$        add.b    d0,d0
  2385.         bcc    17$
  2386.         move.w    d2,12(a1)
  2387.         or.w    d5,12(a2)
  2388.  
  2389. 17$        add.b    d0,d0
  2390.         bcc    18$
  2391.         move.w    d2,14(a1)
  2392.         or.w    d5,14(a2)
  2393.  
  2394. 18$        lea    16(a1),a1
  2395.         lea    16(a2),a2
  2396.         dbra    d1,SprELoop
  2397.         rts
  2398.  
  2399. ; Multicolor-Sprite: 3 Byte mit je 4 Pixeln konvertieren
  2400. SprMulti    btst    d6,MXE(a4)    ;X-expandiert?
  2401.         bne    SprMultiExp
  2402.  
  2403.         moveq    #0,d5
  2404.         bset    d6,d5
  2405.         lsl.w    #8,d5
  2406.         bset    d6,d5        ;d5: Bitmaske für Kollisionspuffer
  2407.  
  2408.         moveq    #2,d1        ;Bytezähler
  2409. SprMLoop    move.b    (a0)+,d0    ;Byte lesen
  2410.         beq    50$        ;Null: Nichts darstellen
  2411.  
  2412.         add.b    d0,d0
  2413.         bcc    11$
  2414.         or.w    d5,(a2)
  2415.         add.b    d0,d0
  2416.         bcc    12$
  2417.         move.w    d4,(a1)        ;11
  2418.         bra    20$
  2419. 12$        move.w    d2,(a1)        ;10
  2420.         bra    20$
  2421. 11$        add.b    d0,d0
  2422.         bcc    20$
  2423.         move.w    d3,(a1)        ;01
  2424.         or.w    d5,(a2)
  2425.  
  2426. 20$        add.b    d0,d0
  2427.         bcc    21$
  2428.         or.w    d5,2(a2)
  2429.         add.b    d0,d0
  2430.         bcc    22$
  2431.         move.w    d4,2(a1)
  2432.         bra    30$
  2433. 22$        move.w    d2,2(a1)
  2434.         bra    30$
  2435. 21$        add.b    d0,d0
  2436.         bcc    30$
  2437.         move.w    d3,2(a1)
  2438.         or.w    d5,2(a2)
  2439.  
  2440. 30$        add.b    d0,d0
  2441.         bcc    31$
  2442.         or.w    d5,4(a2)
  2443.         add.b    d0,d0
  2444.         bcc    32$
  2445.         move.w    d4,4(a1)
  2446.         bra    40$
  2447. 32$        move.w    d2,4(a1)
  2448.         bra    40$
  2449. 31$        add.b    d0,d0
  2450.         bcc    40$
  2451.         move.w    d3,4(a1)
  2452.         or.w    d5,4(a2)
  2453.  
  2454. 40$        add.b    d0,d0
  2455.         bcc    41$
  2456.         or.w    d5,6(a2)
  2457.         add.b    d0,d0
  2458.         bcc    42$
  2459.         move.w    d4,6(a1)
  2460.         bra    50$
  2461. 42$        move.w    d2,6(a1)
  2462.         bra    50$
  2463. 41$        add.b    d0,d0
  2464.         bcc    50$
  2465.         move.w    d3,6(a1)
  2466.         or.w    d5,6(a2)
  2467.  
  2468. 50$        addq.l    #8,a1
  2469.         addq.l    #8,a2
  2470.         dbra    d1,SprMLoop
  2471. SpriteDone1    rts
  2472.  
  2473. ; X-expandiertes Multicolor-Sprite: 3 Byte mit je 4 Pixeln konvertieren
  2474. SprMultiExp    cmp.w    #DisplayX-48,d5    ;Sprite sichtbar?
  2475.         bhs    SpriteDone1
  2476.  
  2477.         moveq    #0,d5
  2478.         bset    d6,d5
  2479.         lsl.w    #8,d5
  2480.         bset    d6,d5
  2481.         move.w    d5,d0
  2482.         swap    d5
  2483.         move.w    d0,d5        ;d5: Bitmaske für Kollisionspuffer
  2484.  
  2485.         move.w    d2,d0        ;d2 auf Langwort erweitern
  2486.         swap    d2
  2487.         move.w    d0,d2
  2488.  
  2489.         moveq    #2,d1
  2490. SprMELoop    move.b    (a0)+,d0    ;Byte lesen
  2491.         beq    50$        ;Null: Nichts darstellen
  2492.  
  2493.         add.b    d0,d0
  2494.         bcc    11$
  2495.         or.l    d5,(a2)
  2496.         add.b    d0,d0
  2497.         bcc    12$
  2498.         move.l    d4,(a1)        ;11
  2499.         bra    20$
  2500. 12$        move.l    d2,(a1)        ;10
  2501.         bra    20$
  2502. 11$        add.b    d0,d0
  2503.         bcc    20$
  2504.         move.l    d3,(a1)        ;01
  2505.         or.l    d5,(a2)
  2506.  
  2507. 20$        add.b    d0,d0
  2508.         bcc    21$
  2509.         or.l    d5,4(a2)
  2510.         add.b    d0,d0
  2511.         bcc    22$
  2512.         move.l    d4,4(a1)
  2513.         bra    30$
  2514. 22$        move.l    d2,4(a1)
  2515.         bra    30$
  2516. 21$        add.b    d0,d0
  2517.         bcc    30$
  2518.         move.l    d3,4(a1)
  2519.         or.l    d5,4(a2)
  2520.  
  2521. 30$        add.b    d0,d0
  2522.         bcc    31$
  2523.         or.l    d5,8(a2)
  2524.         add.b    d0,d0
  2525.         bcc    32$
  2526.         move.l    d4,8(a1)
  2527.         bra    40$
  2528. 32$        move.l    d2,8(a1)
  2529.         bra    40$
  2530. 31$        add.b    d0,d0
  2531.         bcc    40$
  2532.         move.l    d3,8(a1)
  2533.         or.l    d5,8(a2)
  2534.  
  2535. 40$        add.b    d0,d0
  2536.         bcc    41$
  2537.         or.l    d5,12(a2)
  2538.         add.b    d0,d0
  2539.         bcc    42$
  2540.         move.l    d4,12(a1)
  2541.         bra    50$
  2542. 42$        move.l    d2,12(a1)
  2543.         bra    50$
  2544. 41$        add.b    d0,d0
  2545.         bcc    50$
  2546.         move.l    d3,12(a1)
  2547.         or.l    d5,12(a2)
  2548.  
  2549. 50$        lea    16(a1),a1
  2550.         lea    16(a2),a2
  2551.         dbra    d1,SprMELoop
  2552.         rts
  2553.  
  2554.  
  2555. **
  2556. ** Konstanten
  2557. **
  2558.  
  2559. ; Farbpalette
  2560.         CNOP    0,4
  2561. Palette        dc.b    0,0,0,0        ;Schwarz
  2562.         dc.b    255,255,255,0    ;Weiß
  2563.         dc.b    204,0,0,0    ;Rot
  2564.         dc.b    0,255,204,0    ;Cyan
  2565.         dc.b    255,0,255,0    ;Magenta
  2566.         dc.b    0,204,0,0    ;Grün
  2567.         dc.b    0,0,204,0    ;Blau
  2568.         dc.b    255,255,0,0    ;Gelb
  2569.         dc.b    255,128,0,0    ;Orange
  2570.         dc.b    128,64,0,0    ;Braun
  2571.         dc.b    255,128,128,0    ;Hellrot
  2572.         dc.b    64,64,64,0    ;Dunkelgrau
  2573.         dc.b    128,128,128,0    ;Mittelgrau
  2574.         dc.b    128,255,128,0    ;Hellgrün
  2575.         dc.b    128,128,255,0    ;Hellblau
  2576.         dc.b    192,192,192,0    ;Hellgrau
  2577.  
  2578. ; Tabelle der Display-Routinen
  2579. DispProcTab    dc.l    TextStd
  2580.         dc.l    TextMulti
  2581.         dc.l    BitMapStd
  2582.         dc.l    BitMapMulti
  2583.         dc.l    TextECM
  2584.         dc.l    BlackScreen
  2585.         dc.l    BlackScreen
  2586.         dc.l    BlackScreen
  2587.  
  2588.  
  2589. **
  2590. ** Datenbereich
  2591. **
  2592.  
  2593. ; Taglist für den Screen (Amiga)
  2594. ScreenTags    dc.l    SA_DisplayID
  2595. ScreenDID    dc.l    0
  2596.         dc.l    SA_Width,$180    ;Vielfaches von 32
  2597.         dc.l    SA_Height,DisplayY
  2598.         dc.l    SA_Depth,4
  2599.         dc.l    SA_Quiet,-1
  2600.         dc.l    SA_AutoScroll,-1
  2601.         dc.l    SA_Overscan,OSCAN_STANDARD
  2602.         dc.l    0,0
  2603.  
  2604. ; Taglist für das Fenster (Picasso/Amiga)
  2605. WindowTags    dc.l    WA_Left,0
  2606.         dc.l    WA_Top,0
  2607.         dc.l    WA_Width
  2608. WindowWidth    dc.l    0
  2609.         dc.l    WA_Height
  2610. WindowHeight    dc.l    0
  2611.         dc.l    WA_NoCareRefresh,-1
  2612.         dc.l    WA_Borderless,-1
  2613.         dc.l    WA_Activate,-1
  2614.         dc.l    WA_RMBTrap,-1
  2615.         dc.l    WA_CustomScreen
  2616. WindowScreen    dc.l    0
  2617.         dc.l    WA_IDCMP,IDCMP_MOUSEBUTTONS|IDCMP_RAWKEY
  2618.         dc.l    0,0
  2619.  
  2620. ; Struktur für E_OpenScreen (EGS)
  2621. NewEScreen    dc.l    ModeNameBuf+16
  2622.         dc.w    8,0    ;Tiefe 8
  2623.         dc.l    0
  2624.         dc.l    0
  2625.         dc.l    0
  2626.         dc.l    0
  2627.         dc.l    E_eMOUSEBUTTONS|E_eRAWKEY
  2628.         dc.l    0
  2629.  
  2630. ; Taglist für den Screen (Picasso)
  2631. VilTags        dc.l    TAVIS_DM_STRUCT,Dimensions
  2632.         dc.l    TAVIS_DOUBLE_BUFFER,-1
  2633.         dc.l    0,0
  2634.  
  2635. ; VilIntuiSup-Dimensions (Picasso)
  2636. Dimensions    dc.w    0,0,0,0,8,0    ;8: Tiefe
  2637.  
  2638. ; Variablen
  2639.         CNOP    0,4
  2640. DisplayID    dc.l    0    ;Prefs: DisplayID des Screens
  2641. TheScreen    dc.l    0    ;Screen
  2642. TheWindow    dc.l    0    ;Window (Picasso/Amiga)
  2643. EGSPort        dc.l    0    ;EDCMP-Port (EGS)
  2644. WindowPort    dc.l    0    ;IDCMP-Port (Amiga/Picasso)
  2645. TheRastPort    dc.l    0    ;RastPort (Amiga)
  2646. TheViewPort    dc.l    0    ;ViewPort (Amiga/Picasso)
  2647. InvisibleMap    dc.l    0    ;Zeiger auf unsichtbare BitMap
  2648. InvBufNum    dc.l    0    ;Nummer des unsichtbaren Puffers (Picasso)
  2649. VBlankProc    dc.l    0    ;Zeiger auf VBlank-Routine
  2650. DisplayProc    dc.l    0    ;Zeiger auf die Display-Routine (Text/Bitmap etc.)
  2651.  
  2652. ComparisonBuf    dc.l    0    ;Puffer für c2p4
  2653. GfxSet        dc.l    0    ;Signal für c2p4
  2654. GfxSig        dc.w    0
  2655.  
  2656. ScreenType    dc.w    0    ;Prefs: Typ der Screen-Ansteuerung
  2657. NormalCycles    dc.w    0    ;Prefs: Anzahl 6510-Zyklen pro Rasterzeile
  2658. BadLineCycles    dc.w    0    ;Prefs: Anzahl 6510-Zyklen in einer Bad Line
  2659. CiaVABase    dc.w    0    ;16-Bit Basisadresse durch Cia-VA14/15
  2660. ScreenX        dc.w    0    ;Ausmaße des Screens
  2661. ScreenY        dc.w    0
  2662. MustWaitForC2P    dc.w    0    ;Es muß auf das Signal von c2p gewartet werden
  2663.  
  2664.         CNOP    0,4
  2665. Registers    ds.b    128    ;VIC-Register
  2666. MatrixLine    ds.b    40    ;Eine Bildschirmzeile
  2667. ColorLine    ds.b    40    ;Eine Farb-RAM-Zeile
  2668.  
  2669. **
  2670. ** Nicht initialisierte Daten
  2671. **
  2672.  
  2673.         SECTION    "BSS",BSS
  2674. LineStore    ds.b    DisplayX    ;Puffer für eine Zeile
  2675. SprCollBuf    ds.b    DisplayX    ;Puffer für Sprite-Kollisionen
  2676.  
  2677. SprCollTab    ds.b    256        ;Welche Bitkombinationen lösen eine Kollision aus?
  2678.  
  2679. ModeNameBuf    ds.b    nif_SIZEOF    ;Puffer für GetDisplayInfoData
  2680. TheRect        ds.b    ra_SIZEOF    ;Puffer für QueryOverscan
  2681.         END
  2682.